I am looking to create an additional variable that show the list of variables that have the missing values. Is it possible?
data have;
input id x1 y1 z1 ;
cards;
106 1 . 2
107 3 . .
108 . . .
109 1 2 3
;
run;
Have:
Want
In the 'Have' dataset For example: for 106 subject missing values for x1, y1, z1. then I am expecting to create a variable 'missvar' with variable list separated by delimiter of any kind. is this possible to achieve? Thanks
Try this
data have;
input id x1 y1 z1 ;
cards;
106 1 . 2
107 3 . .
108 . . .
109 1 2 3
;
data want;
set have;
array a x1 -- z1;
length missvar $200;
do over a;
if a = . then missvar = catx(', ', missvar, vname(a));
end;
run;
Try this
data have;
input id x1 y1 z1 ;
cards;
106 1 . 2
107 3 . .
108 . . .
109 1 2 3
;
data want;
set have;
array a x1 -- z1;
length missvar $200;
do over a;
if a = . then missvar = catx(', ', missvar, vname(a));
end;
run;
It worked. Thank you.
Anytime 🙂
I'm curious, @SASuserlot , how does having such a text string such as 'x1,y1,z1' help anything? What will you do with it once you create it?
This is an example simulate my data to check data errors. We have have two questions which gate the next set of Numeric Score for next set of question.
Q1, Q2 are Yes or No questions. Q3,Q4, Q5---Q100 are numeric scores questions. Q3, Q4, Q5---Q100 and Q Total, only given score when at least Q1 or Q2 Need to be 'Yes'. 'Q total' only Calculated when all the questions are answered.
So we have the followinng situations where
Q1='Y' and Q2='Y' but some 'Qx' missing the scores and Q total was created. We need to output the list of all those questions missing the scores as list showing why it's a data error with flags in xlsx file.
I hope it makes some kind of sense.
@SASuserlot beware that there is a difference between your have data in the image and your posted data step.
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.