BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
skatethejake
Fluorite | Level 6

Hi All,

 

Just trying to see if there is a way to search for missing characters within this list. When I output the data, take still comes out to be complete even if there is a missing value in score 2. I thought the syntax below but I guess missing() only returns for one variable because when I run the data the only one that will come out incomplete when there is a missing score is score 1. What do I have to do in order to just search multiple variables? I know the easy answer would just be to do an OR clause but let's assume there are tons of scores. would it really be necessary to right 20 different OR's?

 

 

 

data udemy.scoredata_all;
set udemy.score_data;
if not missing(score1-score3) then take = 'complete';
else take = 'incomplete';
run;

 

Best, 

Jake 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

One option:

data have;
  input score1 score2 score3;
  datalines;
1 2 3
. 2 3
1 . 3
1 . .
. . .
. . 3
;

data want;
  set have;
  length take $10.;
  if n(score1,score2,score3) = 3 then
    take = 'complete';
  else take = 'incomplete';
run;

proc print data=want;
run;

You could also use cmiss() or nmiss() instead of n() but not missing() because this function can only take one argument (variable).

Here two ways using cmiss()

data want;
  set have;
  length take $10.;
/*  if cmiss(of score1-score3) = 0 then*/
  if cmiss(of score:) = 0 then
    take = 'complete';
  else take = 'incomplete';
run;

 

From the documentation here:

Comparisons
The MISSING function can have only one argument. The CMISS function can have multiple arguments and returns a count of the missing values. The NMISS function requires numeric arguments and returns the number of missing values in the list of arguments.

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

One option:

data have;
  input score1 score2 score3;
  datalines;
1 2 3
. 2 3
1 . 3
1 . .
. . .
. . 3
;

data want;
  set have;
  length take $10.;
  if n(score1,score2,score3) = 3 then
    take = 'complete';
  else take = 'incomplete';
run;

proc print data=want;
run;

You could also use cmiss() or nmiss() instead of n() but not missing() because this function can only take one argument (variable).

Here two ways using cmiss()

data want;
  set have;
  length take $10.;
/*  if cmiss(of score1-score3) = 0 then*/
  if cmiss(of score:) = 0 then
    take = 'complete';
  else take = 'incomplete';
run;

 

From the documentation here:

Comparisons
The MISSING function can have only one argument. The CMISS function can have multiple arguments and returns a count of the missing values. The NMISS function requires numeric arguments and returns the number of missing values in the list of arguments.

Astounding
PROC Star

@Patrick already gave you an excellent answer.  Just to elaborate on one point ...

 

In your original program, the value that you evaluated was score1-score3.  This is interpreted as score1 minus score3, which is why score2 played no role in the outcome.

Reeza
Super User

This portion is the issue:

missing(score1-score3)

score1-score3 is interpreted by SAS as score1-score3. 

 

I think instead you intended to do the following, but unfortunately that's also not valid for the MISSING() function. 

missing(of score1-score3)

So what you want instead is the NMISS() function which checks for missing or CMISS() for character variables. 

if nmiss(of score1-score3)...

@skatethejake wrote:

Hi All,

 

Just trying to see if there is a way to search for missing characters within this list. When I output the data, take still comes out to be complete even if there is a missing value in score 2. I thought the syntax below but I guess missing() only returns for one variable because when I run the data the only one that will come out incomplete when there is a missing score is score 1. What do I have to do in order to just search multiple variables? I know the easy answer would just be to do an OR clause but let's assume there are tons of scores. would it really be necessary to right 20 different OR's?

 

 

 

data udemy.scoredata_all;
set udemy.score_data;
if not missing(score1-score3) then take = 'complete';
else take = 'incomplete';
run;

 

Best, 

Jake 

 


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 769 views
  • 2 likes
  • 4 in conversation