DATA Step, Macro, Functions and more

How to retain format after proc transpose

Reply
Contributor
Posts: 21

How to retain format after proc transpose

* 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;

 

 

Esteemed Advisor
Posts: 5,621

Re: How to retain format after proc transpose

Posted in reply to Arun_shSAS

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;

PG
Ask a Question
Discussion stats
  • 1 reply
  • 155 views
  • 1 like
  • 2 in conversation