BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi, Below is the input dataset1 which needs to be transformed to dataset2.
Is there a simpler way to do this, please comment.

dataset1
======
KEY VALUE
100 VALUE1,VALUE1A
100 VALUE2,VALUE2A
100 VALUE3,VALUE3A
200 VALUE11,VALUE1B
200 VALUE12,VALUE2B
300 VALUE23,VALUE1C

dataset2
======
KEY NEW_VALUE
100 VALUE1,VALUE1A,VALUE2,VALUE2A,VALUE3,VALUE3A
200 VALUE11,VALUE1B,VALUE12,VALUE2B
300 VALUE23,VALUE1C
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi:
There are some very good PROC TRANSPOSE examples in the documentation -- they wouldn't get you to this output immediately (initially, you'd have COL1, COL2, COL3, COL4, etc, etc instead of NEW_VALUE), but then you could use an ARRAY to create the new variable. Or you could just use BY group processing with the RETAIN statement to construct dataset2 from dataset1.

cynthia
deleted_user
Not applicable
Hi Kumar,

Please try this code.It will be giving exact output.

data one;
input KEY VALUE$ 15.;
cards;
100 VALUE1,VALUE1A
100 VALUE2,VALUE2A
100 VALUE3,VALUE3A
200 VALUE11,VALUE1B
200 VALUE12,VALUE2B
300 VALUE23,VALUE1C
;
run;
proc transpose data=one out=two;
var value;
by key;
run;

data three(drop=_Name_ col1 col2 col3);
set two;
new_column=col1||","||col2||","||col3;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 473 views
  • 0 likes
  • 2 in conversation