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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 421 views
  • 1 like
  • 3 in conversation