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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

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;

View solution in original post

1 REPLY 1
stat_sas
Ammonite | Level 13

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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1043 views
  • 0 likes
  • 2 in conversation