DATA Step, Macro, Functions and more

A Data manupulation question with open number of variables

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

A Data manupulation question with open number of variables

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.


Accepted Solutions
Solution
‎10-23-2014 05:21 PM
Trusted Advisor
Posts: 1,228

Re: A Data manupulation question with open number of variables

Posted in reply to need_sas_help

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


All Replies
Solution
‎10-23-2014 05:21 PM
Trusted Advisor
Posts: 1,228

Re: A Data manupulation question with open number of variables

Posted in reply to need_sas_help

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;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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