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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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