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
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.
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.
@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.
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
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.