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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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