BookmarkSubscribeRSS Feed
Sean100
Calcite | Level 5

Hi,

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);

    else do

        my_character_macro(dataset, current variable, date_var);

    current variable = next variable

%mend

 

Apologies for the sloppy pseudo code! 

2 REPLIES 2
Astounding
PROC Star

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_)

characters (keep=_character_);

set have;

run;

 

Now you are guaranteed that every variable in one data set is numeric, and every variable in the other data set is character.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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:

https://stats.idre.ucla.edu/sas/faq/how-can-i-see-the-number-of-missing-values-and-patterns-of-missi...

 

You can use means, summary, freq, datastep, sql, etc.

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 611 views
  • 0 likes
  • 3 in conversation