I have the following dataset with character variables (subject, style) and
numeric variables (no1, no2, no3 no4,no5.........n)
subject style no1 no2a no3h no4u no5t
------- ----- --- --- ---- ---- ---
1023 PN 0 1 4 2 9
1023 SN 0 . . . .
1098 PN 1 5 6 7 8
1098 SN 0 0 . . 0
I need to create a data set where if all the numeric variables (no1, no2a, no3h, no4u, no5t...n)
have 0 or 1 for the same row then that row needed to be deteled. I can not specity the variable name
in the program and I have to use the code inside a macro and the number of the variable can anything.
I think there might be a way to do something like:
if n01*no2*........*no5t*.....n <1 then detele.
But not sure how to put in a code to execute.
The result dataset should be as below:
subject style no1 no2a no3h no4u no5t
------- ----- --- --- ---- ---- ---
1023 PN 0 1 4 2 9
1098 PN 1 5 6 7 8
Thank you so much from the bottom of my heart.
data have;
infile datalines missover;
input subject $ style $ no1 no2a no3h no4u no5t;
datalines;
1023 PN 0 1 4 2 9
1023 SN 0 . . . .
1098 PN 1 5 6 7 8
1098 SN 0 0 . . 0
;
data want;
set have;
cnt=0;
array no(*) _numeric_;
do i=1 to dim(no);
if no{i} not in (0,1,.) then cnt+1;
end;
if cnt>0;
run;
data have;
infile datalines missover;
input subject $ style $ no1 no2a no3h no4u no5t;
datalines;
1023 PN 0 1 4 2 9
1023 SN 0 . . . .
1098 PN 1 5 6 7 8
1098 SN 0 0 . . 0
;
data want;
set have;
cnt=0;
array no(*) _numeric_;
do i=1 to dim(no);
if no{i} not in (0,1,.) then cnt+1;
end;
if cnt>0;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.