Question

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?

Was it helpful?

Solution

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

OTHER TIPS

You can do it with arrays.

Here is a macro that makes everything in the PDV missing. The parameter t is to allow you to call it multiple times from a single data step.


%macro cleanpdv(t);
array __c&t{*} _character_;
array __n&t{*} _numeric_;
do __i&t=1 to dim(__c&t);
  call missing(__c&t{__i&t});
end;
do __i&t=1 to dim(__n&t);
  call missing(__n&t{__i&t});
end;
drop __i&t;
%mend;

You might use it like this:



Data example2;
var1='A';
Var2='B';
Var3='C';
/* etc*/
output;
%cleanpdv(1);
Var1='B';
output;
%cleanpdv(2);
output;
stop;
run;

which produces the following data set:

  Obs    var1    Var2    Var3

   1      A       B       C
   2      B
   3
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top