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

Can anybody give me the explanation to why the values nn2 and n3 are retained in this do while statement?

 

data test;
n=0;
   do while(n<5);
      put n=;
      n+1;
	  if n=1 then n2=1;
	  if n=2 then n3=2;
	  output;
	end;
run;

Udklip.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

The PDV, that is, the vector holding values for the currently processed observation is only cleared

when the interpreter meets the run instruction. Here, you are always processing the same observation that

you modify and output several times. There is no reason for the values of n2 and n3 to be reset.

View solution in original post

4 REPLIES 4
WarrenKuhfeld
Rhodochrosite | Level 12

You have a one pass data step.  It never goes back for a second pass becasue there is not input data set.  Nothing is retained (in the normal SAS sense).  Nothing is reinitialized to missing for the second pass, because there is no second pass.

rudfaden
Pyrite | Level 9

Are you saying it is because sas keeps n2 and n3 in memory and then keeps priting the same values?

gamotte
Rhodochrosite | Level 12

Hello,

 

The PDV, that is, the vector holding values for the currently processed observation is only cleared

when the interpreter meets the run instruction. Here, you are always processing the same observation that

you modify and output several times. There is no reason for the values of n2 and n3 to be reset.

ballardw
Super User

Maybe this adds a bit to what goes on:

data test;
n=0;
   do while(n<5);
      put n=;
      n+1;
	  if n=1 then n2=1;
          else n2=.;
	  if n=2 then n3=2;
          else n3=.;
	  output;
	end;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 891 views
  • 1 like
  • 4 in conversation