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

Hi,

I have a dataset that I want to generate individual level dataset. I could do this by proc sort, data (retain, first.id) but I think proc sql would be more efficient in coding (some may not agree with this). Thanks

 

Currently I have

ID    flag1 flag2  flag3

1     1       0         1

1     0       1         0

2     1       1         0

2     0        1        0

 

I would want the output to look like

ID    flag1 flag2  flag3

1     1          1       1

2     1          1       0

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @avepo In my humble opinion, i would think you are better off using proc means/summary as you can take advantage of using variable lists and not bother typing max(var) one by one forever if you happen to have numerous flag vars.

 

Also it helps lazy people like me at best

 

data have;
input ID    flag1 flag2  flag3;
cards;
1     1       0         1
1     0       1         0
2     1       1         0
2     0        1        0
;

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

View solution in original post

3 REPLIES 3
kiranv_
Rhodochrosite | Level 12

something like

 

proc sql;

select ID ,   max(flag1) as flag1, max( flag2 ) as flag2, max(flag3) as flag3

from have

group by id;

 

 

novinosrin
Tourmaline | Level 20

Hi @avepo In my humble opinion, i would think you are better off using proc means/summary as you can take advantage of using variable lists and not bother typing max(var) one by one forever if you happen to have numerous flag vars.

 

Also it helps lazy people like me at best

 

data have;
input ID    flag1 flag2  flag3;
cards;
1     1       0         1
1     0       1         0
2     1       1         0
2     0        1        0
;

proc means data=have nway noprint;
class id;
var flag:;
output out=want(drop=_:) max=;
run;
avepo
Fluorite | Level 6

Thank you both!

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