BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jbd13
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

3 REPLIES 3
ballardw
Super User

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;

jbd13
Calcite | Level 5

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.

Patrick
Opal | Level 21

Could you please mark the question as answered?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 3 replies
  • 1275 views
  • 0 likes
  • 3 in conversation