Hi,
Basically, I am trying to figure out two things from the code below:
1. Using @ after num in the input holds num or id when reading the rest of line.
2 Why I get different results when I use input num @ after the do while than if I use input num. I get expected results when using @ but still would be helpful if someone could tell why can not I avoid using @.
Data test;
infile datalines Missover;
input id num @; /*this holds the current num record*/
nump = 0; /*initiate nump*/
do while (num ne .);
nump + 1 ; /* increment nump by 1 if num is ne .*/
output;
input num @;
end;
datalines;
100 1 2 3
101 4 5
102 6 7 8 9 10
;
proc print;run;
You need the @ to continue to read from the same line.
Note that in general you should use TRUNCOVER instead of MISSOVER, but since you are using list mode input it will not matter in this program.
What happens when there are no values for NUM? Your program will not output any observation for such a line. You might want to change from WHILE () to UNTIL () so that you will get one observation with NUM=. .
You can have the DO loop do the counting for you.
do nump=1 by 1 until (num ne .);
output;
input num @;
end;
With the @ in the loop, you are always reading from the same line. But without the @, the first time you go through the loop, you are reading the same line as the first input statement because it ended by @. The second time you execute the loop, in the absence of a trailling @ you are reading the next line, because the last input statement didn't end with a @.
hth
PG
You need the @ to continue to read from the same line.
Note that in general you should use TRUNCOVER instead of MISSOVER, but since you are using list mode input it will not matter in this program.
What happens when there are no values for NUM? Your program will not output any observation for such a line. You might want to change from WHILE () to UNTIL () so that you will get one observation with NUM=. .
You can have the DO loop do the counting for you.
do nump=1 by 1 until (num ne .);
output;
input num @;
end;
You mean
until (num eq .)
PG
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.