DATA Step, Macro, Functions and more

how to keep the original format in the dataset before traanspose

Reply
Occasional Contributor
Posts: 18

how to keep the original format in the dataset before traanspose

dataset contains the followwing values:
tem1
year acct1 acct2 acct3

2001 $100.0 200 $300
2002 $400 500 $600


after transpose:

proc transpose data=tem1 out=tem ;
id year;

run;

2001 2002
acct1 100 400
acct2 200 500
acct3 300 600

what I am expecting after the transpose:


2001 2002
acct1 $100 $400
acct2 200 500
acct3 $300 $600

question:

how can i keep the original format of the data? such as the $100..
Super Contributor
Super Contributor
Posts: 365

Re: how to keep the original format in the dataset before traanspose

Hello Jdk 123,

It is impossible to have different formats for different observations for the same variable. So it is only possible to emulate this:
[pre]
data tem1;
input year acct1 $ acct2 $ acct3 $;
datalines;
2001 $100.0 200 $300
2002 $400 500 $600
run;
proc transpose data=tem1 out=tem ;
id year;
var acct1 acct2 acct3;
run;
[/pre]
Sincerely,
SPR
Occasional Contributor
Posts: 18

Re: how to keep the original format in the dataset before traanspose

Thanks so lot.you have been great help.
Super User
Posts: 9,681

Re: how to keep the original format in the dataset before traanspose

I am confused .But my code work fine.
If you also have problem ,can manually to format them
format _: dollar10. ;


[pre]
data temp;
input year (acct1 acct2 acct3 ) ( : dollar10.);
format acct: dollar10.;
datalines;
2001 $100.0 200 $300
2002 $400 500 $600
run;
proc transpose data=temp out=tem ;
id year;
run;
proc print noobs;run;




_NAME_ _2001 _2002

acct1 $100 $400
acct2 $200 $500
acct3 $300 $600
[/pre]




Ksharp
Ask a Question
Discussion stats
  • 3 replies
  • 209 views
  • 0 likes
  • 3 in conversation