BookmarkSubscribeRSS Feed
adityaa9z
Obsidian | Level 7
Hello everyone,

Has anyone worked on a macro before that helps us identify missing values for different column in a dataset. Hoping to get an intuitive macro which tells how many and row number where values are missing. Example Name Age Sex.

If there are 2 values missing in name, 4 in age and 5 in sex, the macro should be able to tell this info.

Planning to use in my code once the final dataset is ready so I can just run this macro and check for missing fields, values.
5 REPLIES 5
adityaa9z
Obsidian | Level 7
Hi. I have to use it on a daily basis for different datasets so adding this code doesn't seem a viable solution which I why was hoping for a macro instead.
PaigeMiller
Diamond | Level 26

@adityaa9z wrote:
Hi. I have to use it on a daily basis for different datasets so adding this code doesn't seem a viable solution which I why was hoping for a macro instead.

But the code will work on every data set, regardless of variable names. How can code that works on every data set, regardless of variable names, not be viable?

--
Paige Miller
Ksharp
Super User
%macro check_miss(dsn= , out= );
/* firstl, get variable names */
proc transpose data=&dsn(obs=0) out=vname;
var _all_;
run;
/* then check if variable is all missing */
proc sql noprint;
select catx(' ','nmiss(',_name_,') as',_name_) into :vnames separated by ','
from vname;
create table temp as
select &vnames from have;
quit;
proc transpose data=temp out=&out;
var _all_;
run;
%mend;




/*Test Macro*/
data have;
 set sashelp.class;
 if _n_ in ( 1 4 6) then call missing(name,age);
run;
%check_miss(dsn=have, out=want)
bknitch
Quartz | Level 8

Check out this article, it may be of some use to you.

https://www.lexjansen.com/nesug/nesug06/cc/cc12.pdf

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 630 views
  • 0 likes
  • 4 in conversation