tags:

views:

124

answers:

2

Is there a command or a quick way to set all the existing variables in the PDV to missing?

I have some code which runs like this:

Data example2; 
var1='A';
Var2='B';
Var3='C';
/* etc*/
output;
Var1='B';
output;
stop;
run;

once the first 'output' statement is reached I'd like to reset all the PDV variables to missing (eg var2=''; var3='';) but without having to manually declare them as such. Can anyone help?

+1  A: 
Simon Nickerson
thanks simonn - some advanced array logic in this solution..
Bazil
actually simonn - I am finding myself using your solution more often than the call missing routine - as your code can be quickly modified to turn all 'missing' variables into zeros.
Bazil
+7  A: 

The call missing routine and the _all_ automatic variable list will do it easily

call missing(of _all_);

For example

Data example2;
var1='A';
Var2='B';
Var3='C';
output;
call missing(of _all_);
Var1='B';
output;
stop;
run;

proc print data=example2;
run;

produces

                                 The SAS System

                               Obs    var1    Var2    Var3

                                1      A       B       C
                                2      B
cmjohns
I thought call missing would be useful...didn't know about the _all_ keyword...nice
CarolinaJay65
There is also _character_ and _numeric_ automatic variable lists (like simonn used in his answer) if you just want to change just the character variables or just the numeric variables, respectively. Very handy! Here's a reference: http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000695105.htm
cmjohns
very tidy - thankyou!
Bazil
This is much nicer than my solution! I didn't realise you could pass multiple variables to call missing() like that. Thanks!
Simon Nickerson