BookmarkSubscribeRSS Feed
kalbo
Obsidian | Level 7

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!

4 REPLIES 4
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
Tom
Super User Tom
Super User

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.

mnatkins
Calcite | Level 5

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;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 928 views
  • 6 likes
  • 5 in conversation