BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Siddharth123
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

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

PG
Tom
Super User Tom
Super User

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;

PGStats
Opal | Level 21

You mean

until (num eq .)

PG

PG

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 737 views
  • 7 likes
  • 3 in conversation