I would like to create a macro function that counts the number of missing values for a user-specified set of variables within a user-specified data set. I have written the basic procedure to count missing values for a set of variables. I’m using a data step and just keeping the variable I want to count using the keep statement. What I’d really like to do is have the list of variables in the keep statement as a list which is defined elsewhere. I’ve looked at using a variable list but this seems to rely on using some sort of structured nomenclature which is not present in the variable lists I’ll want to pass.
Any help would be greatly appreciated.
How many variables are you trying to pass?
Depending on actual results needed you might be able to simplify using Proc means or summary to count missing. If something like this works:
proc summary data=have;
var <variables go here>;
output out=want nmiss=;
run;
Then a macro variable or parameter may work.
let varlist = age height weight dob;
proc summary data=have;
var &varlist;
output out=want nmiss=;
run;
How many variables are you trying to pass?
Depending on actual results needed you might be able to simplify using Proc means or summary to count missing. If something like this works:
proc summary data=have;
var <variables go here>;
output out=want nmiss=;
run;
Then a macro variable or parameter may work.
let varlist = age height weight dob;
proc summary data=have;
var &varlist;
output out=want nmiss=;
run;
Ah great, that works!
I want to have the option to pass between 5 and 10 variables - I didn't realise you could define a macro variable as a list like that so was facing the same problem using proc summary.
Thank you very much for your help.
Could you please mark the question as answered?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.