Hi guys
I am trying to write simple code to check a numeric variable to see if it has all values missing or not and create a macro variable e.g ALLMISS=Y or N.
Any help would be appreciated.
e.g.
NUMVAR
.
.
.
Thanks!
proc summary data=have;
var numvar;
output out=counts n=n;
run;
If N=0 in the output data set named COUNTS, that's what you're looking for.
Here is a pretty simple/quick way.
data _null_;
if eof then call symputx('allmiss'='Y');
set have(keep=numvar) end=eof;
where not missing(numvar);
call symputx('allmiss','N');
stop;
run;
It will have to scan the whole file to get to YES but only up to the first non missing value to find that the answer is NO.
Another approach is to use Proc SQL:
proc sql noprint;
select case when sum(case when numvar is not null then 1 else 0 end) then 'N' else 'Y' end into :allmiss
from have;
quit;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.