BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10

I have the following data: 

id s1 m1 t1 
1 1   0    0
1 1 1     0
1 1 0    0
2 1 0 1
2  0 1 0

I want to create a dataset that if the value of each of the three variables s1, m1, t1 was once "1" then outpuet "1" row for that id that represent either a 0 or 1 for each id. 

output:

 

id m1 s1 t1 
1 1   1    0
2  1   1   1
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

@lillymaginta wrote:

I have the following data: 

id s1 m1 t1 
1 1   0    0
1 1 1     0
1 1 0    0
2 1 0 1
2  0 1 0

I want to create a dataset that if the value of each of the three variables s1, m1, t1 was once "1" then outpuet "1" row for that id that represent either a 0 or 1 for each id. 

output:

 

id m1 s1 t1 
1 1   1    0
2  1   1   1

It looks to me like you want the max of M1 S1 and T1 for each ID.

 

data s;
   input id s1 m1 t1;
   cards;
1 1   0    0
1 1 1     0
1 1 0    0
2 1 0 1
2  0 1 0
;;;;
   run;
proc print;
   run;
proc summary data=s nway;
   class id;
   output out=max(drop=_:) max(s1 m1 t1)=;
   run;
proc print;
   run;

Capture.PNG

 

 

View solution in original post

3 REPLIES 3
data_null__
Jade | Level 19

@lillymaginta wrote:

I have the following data: 

id s1 m1 t1 
1 1   0    0
1 1 1     0
1 1 0    0
2 1 0 1
2  0 1 0

I want to create a dataset that if the value of each of the three variables s1, m1, t1 was once "1" then outpuet "1" row for that id that represent either a 0 or 1 for each id. 

output:

 

id m1 s1 t1 
1 1   1    0
2  1   1   1

It looks to me like you want the max of M1 S1 and T1 for each ID.

 

data s;
   input id s1 m1 t1;
   cards;
1 1   0    0
1 1 1     0
1 1 0    0
2 1 0 1
2  0 1 0
;;;;
   run;
proc print;
   run;
proc summary data=s nway;
   class id;
   output out=max(drop=_:) max(s1 m1 t1)=;
   run;
proc print;
   run;

Capture.PNG

 

 

lillymaginta
Lapis Lazuli | Level 10

An interesting smart way to think through it, that is simple! thanks! 

Jagadishkatam
Amethyst | Level 16

data have ;
input id s1 m1 t1;
cards;
1 1   0    0
1 1 1     0
1 1 0    0
2 1 0 1
2  0 1 0
;

options missing=0;
data want ;
set have(rename=(s1=s2 m1=m2 t1=t2));
by id;
retain s1 m1 t1;
if first.id then do;
s1=.;
m1=.;
t1=.;
end;
if s2 eq 1 then s1=s2;
if m2 eq 1 then m1=m2;
if t2 eq 1 then t1=t2;
if last.id;
drop s2 m2 t2;
run;

Thanks,
Jag

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 988 views
  • 2 likes
  • 3 in conversation