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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.