BookmarkSubscribeRSS Feed
Arun_shSAS
Fluorite | Level 6

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

 

 

1 REPLY 1
PGStats
Opal | Level 21

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 2227 views
  • 1 like
  • 2 in conversation