Hello
I have data like this :
data temp;
input company$ time earning;
cards;
A 1993 45
A 1994 52
B 1993 42
B 1994 59
run;and i would like to transform the data like this:
1993 1994
A 45 52
B 42 59
How can I do it ? Thanks
You can use next code:
proc transpose data=temp
out=want(drop=_name_) prefix=Y ;
by company;
id time;
var earning;
run;
You can use next code:
proc transpose data=temp
out=want(drop=_name_) prefix=Y ;
by company;
id time;
var earning;
run;
data temp;
input company$ time earning;
cards;
A 1993 45
A 1994 52
B 1993 42
B 1994 59
;
run;
proc sort data=temp;
by company time earning;
run;
proc transpose data=temp out=want;
by company;
id time;
var earning;
run;
Not recommended to have variable names that only include numbers, since not all SAS procedures honor the validvarname=any option. However, that said, the following will do what you want.
Interestingly, in running the following SAS will produce warnings in the log that _1993 and _1994 don't exist, but it does recode the variable names correctly:
data temp;
input company$ time earning;
cards;
A 1993 45
A 1994 52
B 1993 42
B 1994 59
;
run;
proc sort data=temp;
by company time earning;
run;
options validvarname=any;
proc transpose data=temp
out=want(drop=_name_ rename=(_1993='1993'n _1994='1994'n));
by company;
id time;
var earning;
run;
Art, CEO, AnalystFinder.com
Thank you for your patience with so simple problem.
I stand/sit corrected regarding my previous response. When validvarname=any is in effect, proc transpose doesn't preface the new variables with underscores .. which is why the warning occurred when I included the rename option. Only the following was needed:
options validvarname=any;
proc transpose data=temp
out=want(drop=_name_);
by company;
id time;
var earning;
run;
Art, CEO, AnalystFinder.com
ok, thank u very much!
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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.