BookmarkSubscribeRSS Feed
Aexor
Lapis Lazuli | Level 10

Hi I have a datasets having numerous variables and want to compare what are the variables having missing values for a subject.

 

id name number results rank

1  Nan         .          3          A

2  Ben      10          .           

 

want results like with new variable "Comment"

 

id name number results rank   Comment

1  Nan         .          3          A    Number variable is missing

2  Ben      10          .                 Results and rank variable is missing

 

 

Please help

2 REPLIES 2
rmacarthur
Pyrite | Level 9

data want ; set have;
if missing(number) > 0 then comment=" Number variable is missing" ;
if (missing(results) > 0) and (missing(rank) > 0 )
then comment="Results and rank variable is missing" ;
run;

And so on for what ever other combinations of missing variables you'd like to identify

ballardw
Super User

@Aexor wrote:

Hi I have a datasets having numerous variables and want to compare what are the variables having missing values for a subject.

 

id name number results rank

1  Nan         .          3          A

2  Ben      10          .           

 

want results like with new variable "Comment"

 

id name number results rank   Comment

1  Nan         .          3          A    Number variable is missing

2  Ben      10          .                 Results and rank variable is missing

 

 

Please help


I wouldn't bother to try much of an actual narrative sentence because you have potential several different rules to use.

I might start with something like:

data want;
   set have;
   array _nums_ _numeric_;
   array _chars_  _character_;
   length comment $200; /* the length 
   of the comment variable has to be long
   enough to contain the names of ALL the variables
   in your data set + one space to separate them
   PLUS any miscellaneous text
   */
   comment='Vars with missing values are: ';
   do i=1 to dim(_nums_);
      if missing(_nums_[i]) then comment=catx(' ',comment,vname(_nums_[i]));
   end;
   do i=1 to dim(_chars_);
      if missing(_chars_[i]) then comment=catx(' ',comment,vname(_chars_[i]));
   end;
   drop i;

The VNAME function can return the name of an Array referenced variable. The _numeric_ and _character_ are special words to provide access to those types of variables. DO NOT define COMMENT prior to the Array statement or it would be included in the checks for the character variables.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 631 views
  • 1 like
  • 3 in conversation