DATA Step, Macro, Functions and more

Summary of flags

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 104
Accepted Solution

Summary of flags

[ Edited ]

Hi there,

For your kind information, I am trying to create a summary of flags per record where flags are coming from multiple rows for each ID as shown in the data. Can anybody help me to write sascode to move forward to achieve the goal (without splitting and merging the tables)

data have;
input id $ flag1  flag2  flag3 flag4 ;
datalines;
101 1 0 0 1
101 0 1 0 0
102 0 0 0 1
102 0 0 1 0
102 1 0 1 0
103 1 1 0 0
103 1 1 1 0
103 1 0 0 0
;
run;


data want;
input id $ flag1  flag2  flag3 flag4 ;
datalines;
101 1 1 0 1
102 1 0 1 1
103 1 1 1 1
;
run;


Thank you in advance for your kind reply.
Regards, 

Swain

Accepted Solutions
Solution
‎09-22-2017 01:31 PM
Super User
Posts: 11,343

Re: Summary of flags

Posted in reply to DeepakSwain

One way of several

proc summary data=have nway;
   class id;
   var flag: ;
   output out=want (drop=_:) max=;
run;

View solution in original post


All Replies
Solution
‎09-22-2017 01:31 PM
Super User
Posts: 11,343

Re: Summary of flags

Posted in reply to DeepakSwain

One way of several

proc summary data=have nway;
   class id;
   var flag: ;
   output out=want (drop=_:) max=;
run;
Frequent Contributor
Posts: 112

Re: Summary of flags

Posted in reply to DeepakSwain

Another way if you prefer proc sql-

 

proc sql;

create table want as select id, max(flag1) as flag1, max(flag2) as flag2, max(flag3) as flag3, max(flag4) as flag4 from have group by id;

quit;

 

 

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 98 views
  • 2 likes
  • 3 in conversation