data HAVE;
input Group $ _NAME_ $ mth_28FEB2013 mth_31MAR2013;
datalines;
Central AAPP 1000 2500
Pacific BBER 1 100
PACIFIC BRMM 2 150
;
run;
| Group | _NAME_ | mth_28FEB2013 | mth_31MAR2013 |
| Central | AAPP | 1000 | 2500 |
| Pacific | BBER | 1 | 100 |
| PACIFIC | BRMM | 2 | 150 |
I want to transpose based on the month entry(current a character. I would also need to define a new variable called value to "house" the number from the date I need to read it as a date9 as follows
| Group | _NAME_ | Month | Value |
| Central | AAPP | 28FEB2013 | 1000 |
| Central | AAPP | 31MAR2013 | 2500 |
| Pacific | BBER | 28FEB2013 | 1 |
| Pacific | BBER | 31MAR2013 | 100 |
| Pacific | BRMM | 28FEB2013 | 2 |
| Pacific | BRMM | 31MAR2013 | 150 |
Are you able to go back to your raw data? The DATA step can handle this based on the original data:
data want;
input Group $ _NAME_ $ @;
Month = '28FEB2013'd;
input value @;
output;
month = '31MAR2013'd;
input value;
output;
format month date9.;
run;
data HAVE;
input Group $ _NAME_ $ mth_28FEB2013 mth_31MAR2013;
datalines;
Central AAPP 1000 2500
Pacific BBER 1 100
PACIFIC BRMM 2 150
;
run;
proc transpose data=have(rename=(_name_=name)) out=want;
by group name notsorted;
var mth:;
run;
or
data want;
set have;
array j mth:;
do over j;
month=scan(vname(j),-1, '_');
value=j;
output;
end;
drop mth:;
run;
Hi Q,
Before transpose you have to change the Original variable name (_name_) to "name" or any name as per your requirement. Here you can go with a simple solution.
data HAVE;
input Group $ NAME $ mth_28FEB2013 mth_31MAR2013;
datalines;
Central AAPP 1000 2500
Pacific BBER 1 100
PACIFIC BRMM 2 150
;
run;
proc sort data=have;
by Group name;
run;
proc transpose data=have out=have1 (rename=(_name_=month col1=value));
by group name;
var mth_:;
run;
data want (drop=month rename=(month1=month));
set have1;
month1=input(substr(month, find(month, '_', 1)+1), date9.);
format month1 date9.;
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 lock in 2025 pricing—just $495!
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.