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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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