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

I am using SAS 9.4

 

Hello all,

 

I have a data set that is similar to this:

 

ID Med Opioid NSAID Diuretic Steroids
1 A 1 0 0 0
1 B 1 0 0 0
1 C 0 1 0 0
1 D 0 0 1 0
1 E 0 0 0 1
2 D 0 0 1 0
2 C 0 1 0 0
3 A 1 0 0 0
3 I 0 1 0 0
3 J 0 0 0 1
3 D 0 0 1 0
4 A 1 0 0 0
4 B 1 0 0 0
4 N 0 0 1 0

 

and I would like to transform the data set into something that looks like this:

 

ID Opioid NSAID Diuretic Steroids
1 1 1 1 1
2 0 1 1 0
3 1 1 1 1
4 1 0 1 0

 

How would I go about doing this? 

Thank you in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Angel_Larrion
SAS Employee

You can do it with proc sql.

proc sql;
create table want as
select  id, max(Opioid) as opioid, max(NSAID) as NSAID, max(Diuretic) as Diuretic, max(Steroids) as Steroids
from have
group by id;
quit;

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

It all depends on the type of your variables Opioid, NSAID, Diuretic and Steroids. Are they numeric or char?

Angel_Larrion
SAS Employee

You can do it with proc sql.

proc sql;
create table want as
select  id, max(Opioid) as opioid, max(NSAID) as NSAID, max(Diuretic) as Diuretic, max(Steroids) as Steroids
from have
group by id;
quit;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 889 views
  • 4 likes
  • 5 in conversation