Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

do loop prob

Status
Not open for further replies.

bumed

Technical User
Aug 23, 2007
18
US
Hi,
Here is my code:

data arrow4;
set arrow3 (keep = RTc1 outlier accuracy code);
length lastcode $4;
retain lastCode;
if (RTc1^=.) and lastcode = 'altl' then do;
Do i = 1 to *;
Ttype = "AVl(i)";
end;
lastCode = Code;
run;

I'm trying to have Ttype = AVl1, AVl2, so no when the if statement is met. My problem is that I would like the Do loop to go only as many times as the if statement is met. I have tried to use a small number but I get an error (There was 1 unclosed DO block.)
 
I have fix some stuff but im still having trouble with counting a iterations of the data. I would like _N_ to increase each time the if statement is met.

data arrow4;
set arrow3 (keep = RTc1 outlier accuracy code);
length lastcode $4;
retain lastCode;
if lastcode = 'altl' and RTc1^='.' then Ttype = "AVl"_N_;
lastCode = Code;
run;
 
bumed,
In your first post the error you received was correct. You are missing an END statement. There is no END for the IF block that you started.

In your second post you state that you want the _N_ to increase. This is impossible as that variable is a SAS auto variable (its controlled by the SAS system).

Its seems that you want to look through several variables and detirmine the 'last code' that meets your criteria. I don't have enough information on what you want to do, but I don't think that using arrays (That you never declared) is the way to go. How about describing your dataset and your mission (problem) and perhaps we can come up with a way to handle that.
Klaz
 
data arrow4;
set arrow3 (keep = RTc1 outlier accuracy code);
length lastcode $4;
retain lastCode;

if lastcode = 'altl' then Tcount = 1;
Tsum + Tcount;
if (RTc1^=.) then do;
if lastcode = 'altl' then Ttype = "AVL"_Tsum;
end;

I'm trying to label reactions times (RTc1) that met a criteria (RTc1^=. and has a code label altl) with a static label AVL that increases each time the criteria is met.

I have been working on the code and have used a sum statement to count the number of times that an if statement is met. The problem that I'm having now is that I would like the info in Ttype to have a static AVL with Tsum that changes as the count increase. But I don't know how to combine the 2, I keep getting and error saying that AVL_Tsum is unutilized or that there should be some asthmatic.

Thanks for all you help I have been at this program all night.
Steve
 
Ah. What you need is the concatonator symbol. '||'
Code:
  if lastcode = 'altl' then Ttype = "AVL"||left(put(_Tsum,8.));

Is this what you need?
Klaz
 
Thanks for the help. I'm still learning and I didn't know about || and the put statement.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top