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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1212 views
  • 0 likes
  • 2 in conversation