* I want to retain my format of values even after proc transpose how to do that;
data a;
input year groupx respondents resa resb resc;
cards;
2007 5 10 100 . .
2008 4 13 61 23 15
2009 5 13 38 53 7
2010 7 20 60 25 15
;
run;
proc transpose data=a out=b;
run;
proc transpose data=b out=c(drop=_name_);
run;
data d(drop=i resa resb resc);
set c;
format b1 b2 b3 percent6.;
array a[*] resa resb resc ;
array b[3] b1 b2 b3;
do i=1 to 3;
b{i}=a{i}/100;
end;
run;
The format will be retained when the transposed variables share the same format. Look at this example:
data a;
input year groupx respondents resa resb resc;
format resa resb resc z4.0;
cards;
2007 5 10 100 . .
2008 4 13 61 23 15
2009 5 13 38 53 7
2010 7 20 60 25 15
;
proc transpose data=a out=b;
by year groupx respondents notsorted;
var resa resb resc;
run;
proc transpose data=b out=c(drop=_name_);
by year groupx respondents notsorted;
var col1;
id _name_;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.