Help using Base SAS procedures

proc transpose help

Reply
Super Contributor
Posts: 316

proc transpose help

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
Valued Guide
Posts: 632

Re: proc append help

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]
Super Contributor
Posts: 316

Re: proc append help

Thanks for your inputs Art!

btw sorry for the misleading subject. it should be proc transpose
Ask a Question
Discussion stats
  • 2 replies
  • 112 views
  • 0 likes
  • 2 in conversation