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

Hi
Maybe my problem is very simple, but I can't with this!

I have this data set: 

 

IDGenderDisease1
4421390
4421546
4421670
5712980
5711546
8321390

 

I tried with this: 

 

proc traspose data=example out =example1 prefix=disease;

                       var disease;

                       by id;

run; 

 

 

but I want to something like this: 

 

IDGenderDisease1_1Disease1_2Disease1_3
442139015461670
57129801546-
8321390--

 

How can I do it?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You were close, but your variable is called disease1 .. NOT disease. The following should work:

 

proc transpose data=example 
               out =example1 (drop=_:) 
               prefix=disease1_;
  var disease1;
  by id gender;
run; 

Art, CEO, AnalystFinder.com

View solution in original post

3 REPLIES 3
Reeza
Super User

Putting your data in a wide format will make it more difficult to work with in the long run.

It's common, but it's not because it's a good programming method but because it's common....

 

1. Add an counter variable (1,2,3) so SAS knows the prefix needed and to make each row unique, see link if you need help with this.

2. Then do PROC TRANSPOSE and add the variable to your ID list. 

 

proc transpose data=have out=want prefix=disease_;

by id gender; *you may need to sort as well;

var disease;

id counter;

run;

 

art297
Opal | Level 21

You were close, but your variable is called disease1 .. NOT disease. The following should work:

 

proc transpose data=example 
               out =example1 (drop=_:) 
               prefix=disease1_;
  var disease1;
  by id gender;
run; 

Art, CEO, AnalystFinder.com

CarolBarahona
Fluorite | Level 6

Thank you very much!
You right, I was close... but I needed a push!

 

 

 

 

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 984 views
  • 0 likes
  • 3 in conversation