Programming the statistical procedures from SAS

Counting variables of specified by user input

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Counting variables of specified by user input

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.


Accepted Solutions
Solution
‎12-09-2013 01:16 PM
Grand Advisor
Posts: 10,052

Re: Counting variables of specified by user input

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


All Replies
Solution
‎12-09-2013 01:16 PM
Grand Advisor
Posts: 10,052

Re: Counting variables of specified by user input

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;

New Contributor
Posts: 4

Re: Counting variables of specified by user input

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.

Respected Advisor
Posts: 3,759

Re: Counting variables of specified by user input

Could you please mark the question as answered?

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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