04-25-2018 07:08 AM
I have been given a massive table (800+ columns, over 200,000 rows) with both character and numeric columns. I have been asked to find the proportion of missing data in each column, both overall and the average annually, and present the results in a table.
I have written macros for both numeric and character variables which will produce a row of the required data and append it to a table which will become the final table.
However, at the moment I will have to write all 800+ variable names into the macros one by one and then run it all at once.
Is there any way to write a macro that will run through the variables, decide if the current variable is numeric or character, and put it into the appropriate macro?
For example, something like:
%macro master_macro(dataset, date_var);
while(current variable exists)
if the current variable is numeric do
my_numeric_macro(dataset, current variable, date_var);
my_character_macro(dataset, current variable, date_var);
current variable = next variable
Apologies for the sloppy pseudo code!
04-25-2018 07:55 AM
If you search the forum here, you will probably find that this question has been addressed in ways that are shorter ... you don't need to name each variable individually. However, if that doesn't appeal to you, the easiest route might be to divide the variables into separate data sets:
data numerics (keep=_numeric_)
Now you are guaranteed that every variable in one data set is numeric, and every variable in the other data set is character.
04-25-2018 09:28 AM
You do not need macro at all. Your problem can be broken down into two simple steps - get nmiss of number, get nmiss of characters, for instance, produce a report of missing numbers:
proc means data=have nmiss; var _numeric_; run;
There are loads of very simple methodolgies for doing what you want, for instance:
You can use means, summary, freq, datastep, sql, etc.