BookmarkSubscribeRSS Feed
JasonL
Quartz | Level 8

Hi there,

I have data like this:

ID   V1  V2  V3  ...... V20

01   A1  B2  C3  ......

02  O1  P2  Q3  ......

03  X1  Y2  Z3  ......    

......

and need to convert it into something like this:

ID  TheVar

01  A1

01  B2

01  C3

......

02  O1

02  P2

02  Q3

......

03  X1

03  Y2

03  Z3

......

 

Is there an efficient way to do that?  Thank you!

Jason

2 REPLIES 2
ballardw
Super User

Proc transpose:

 

data have;
input iD $   V1 $ v2 $  V3 $;
datalines;
01   A1  B2  C3 
02  O1  P2  Q3  
03  X1  Y2  Z3  
;

proc transpose data=have out=trans (drop=_name_)
  prefix=TheVar
;
by id;
var v1 - v3;
run;

If there are other variables that need to be carried along you need to show a better example.

Please provide data in the form of a data step as shown above and post into a code box opened on the forum using the </> or "running man" icon. Posting the main message window will usually result in text being reformatted and data steps may not run after the forum gets through with them.

JasonL
Quartz | Level 8

Great!  That does it!

Thank you very much!

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 545 views
  • 1 like
  • 2 in conversation