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

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
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

One way of several

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

View solution in original post

2 REPLIES 2
ballardw
Super User

One way of several

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

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;

 

 

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