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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output statement and Do loop

Status
Not open for further replies.

roland9

Technical User
Feb 8, 2006
17
0
0
US
Data:
Each record contains a varying number of values for Activity.

First Five Records

Raw Data File Excdata3

1---+----10---+----20---+----30---+----40
1051 TENNIS SWIMMING AEROBICS
1052 JOGGING BASKETBALL
1053 AEROBICS SWIMMING CYCLING
1054 GOLF JOGGING TENNIS
1055 WALKING AEROBICS


This is the code for the data below

data level_1;
infile excdata3 missover;
input id $ activity :$10.@;
choice=0;
do while (activity ne '');
choice+1;
output;
input activity :$10.@;
end;
run;

I would like the data displayed as

1051 Tennis 1
1051 swimming 2
1051 Areobics 3
1051 Jogging 1

so forth and so on...

1. I am beginner in sas and having a problem understanding the logic of the code (Is there anyway it can be explained in the log).Why is the output statement before the second input and not after the input statement.

2. For a do loop if the condition is true does the loop perform again or you go to the top of the data setp..Any help is appreciated..

Thanks,
Roland



 
OK, this is a fairly simple statement, and what i'd recommend doing to answer question 1, is move the output statement to where you think it should go, and take a look at the output. Playing with code, and breaking it is quite often the best way to understand it.
The trailing @ sign is an important part of this step and it prevent SAS from moving on to the next record, until SAS reaches the end of the datastep. The Do While step needs to have a value in "activity" when it starts, which is why it is read in the first input, and from that point it all logically follows on from the steps before.
Does that help?
I would recommend looking up "trailing @" and "do while" in the SAS doco to get a full understanding of how those things work. I'd also recommend checking out the differences between Do While and Do Until.
 
Thanks ....I read some documentation on the diff in both types as well as the trailing sign and it helped.I learnt even the debug option is useful sometimes to see the flow of logic.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top