Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS . Are variables set to missing at every iteration of a data step?

Tags:

sas

I always thought that the variables are set to missing for every iteration of the data step . However, in the following code, it looks like the value that the variable gets at the very beginning retains. I can't understand why this happens ?

data one;
input x $ y;
datalines;
a 10
a 13
a 14
b 9
;
run;

data two;
input z;
datalines;
45
;
run;

data test;
if _n_ = 1 then set two; /* when _n_=2 the PDV assigns missing values, right ? */
set one;
run;
proc print;
run; 

The outcome is

   z      x     y  
   45     a    10
   45     a    13
   45     a    14
   45     b     9

I was expecting to get this

   z      x     y  
   45     a    10
   .      a    13
   .      a    14
   .      b     9
like image 258
Elvis Avatar asked Dec 15 '14 04:12

Elvis


1 Answers

SAS does not reset the values in PDV for - SET, MERGE, MODIFY, or UPDATE statements. Since you are using SET statement so SAS is not resetting it.

if _n_ = 1 then set two;

http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p08a4x7h9mkwqvn16jg3xqwfxful.htm

Read - The Execution Phase - Pointer 5

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001290590.htm

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000961108.htm

like image 158
in_user Avatar answered Oct 03 '22 04:10

in_user