BookmarkSubscribeRSS Feed
milts
Pyrite | Level 9
hi sas experts,

let's say i have this table

id,tag,num_val,txt_val
1,tag1,1,-
1,tag2,1,-
1,tag3,2,-
2,tag1,3,-
2,tag2,2,-
2,tag3,1,-
2,tag4,,txt

i want to transpose this and have a result like these

id,tag1,tag2,tag3,tag4
1,1,1,2,
2,3,2,1,txt

the value of tag depends on which of num_value and txt_value is not missing on the first dataset

hope for your inputs

thanks,
milton Message was edited by: milts
2 REPLIES 2
ArtC
Rhodochrosite | Level 12
The following should do the trick. I made some minor assumptions about your data.

[pre]
data tags(keep=idnum tag val);
infile datalines dlm=',';
input idnum tag $ num_val txt_val $;
length val $10;
if num_val ne ' ' then val=input(num_val,best.);
else val = txt_val;
datalines;
1,tag1,1,-
1,tag2,1,-
1,tag3,2,-
2,tag1,3,-
2,tag2,2,-
2,tag3,1,-
2,tag4,.,txt
run;

proc transpose data=tags
out=ttags(drop=_name_);
by idnum;
id tag;
var val;
run;
[/pre]
milts
Pyrite | Level 9
Thanks for your inputs Art!

btw sorry for the misleading subject. it should be proc transpose

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 744 views
  • 0 likes
  • 2 in conversation