I have this output:
mean | min_max | median | group |
32 | 1-40 | 35 | Chef/owner |
33 | 2-45 | 31 | Chef's assistant |
31 | 4-39 | 28 | Waiter |
With proc transpose I get this:
_NAME_ | COL1 | COL2 | COL3 |
mean | 32 | 33 | 31 |
min_max | 1-40 | 2-45 | 4-39 |
median | 35 | 31 | 28 |
I would like rename the COL1, COL2, COL3 in the same procedure so it can look like this:
_NAME_ | Chef/owner | Chef's assistant | Waiter |
mean | 32 | 33 | 31 |
min_max | 1-40 | 2-45 | 4-39 |
median | 35 | 31 | 28 |
I need the output to look like this since this will be used in a macro. I want to avoid renaming each col with a specific name since this macro will also be used for other grouping variable (other that chef/owner, chef´s assistant and waiter).
Thanks!
Use the ID statement.
data have;
input mean min_max $ median group $20.;
cards;
32 1-40 35 Chef/owner
33 2-45 31 Chef's assistant
31 4-39 28 Waiter
;
proc transpose data=have out=want;
id group;
var mean min_max median;
run;
proc print;
run;
Of course that will make them all as CHARACTER variables to be able to hold strings like '2-45'. So values like 32 will get converted to
' 32'
And SAS will have to convert those strange group names into actual variable names.
Chef_s_ Obs _NAME_ Chef_owner assistant Waiter 1 mean 32 33 31 2 min_max 1-40 2-45 4-39 3 median 35 31 28
Use the ID statement.
data have;
input mean min_max $ median group $20.;
cards;
32 1-40 35 Chef/owner
33 2-45 31 Chef's assistant
31 4-39 28 Waiter
;
proc transpose data=have out=want;
id group;
var mean min_max median;
run;
proc print;
run;
Of course that will make them all as CHARACTER variables to be able to hold strings like '2-45'. So values like 32 will get converted to
' 32'
And SAS will have to convert those strange group names into actual variable names.
Chef_s_ Obs _NAME_ Chef_owner assistant Waiter 1 mean 32 33 31 2 min_max 1-40 2-45 4-39 3 median 35 31 28
Why would you do such a transpose in the first place? If you are doing this to create a report, don't transpose, use PROC REPORT. You will have many more options for controlling the column names. Please let us know if you are trying to create a report.
Personally I find any variable that has two values, i.e. Min and MAX in a single variable basically a failure waiting to happen.
Are you sure that you need a data set? It might be easier, especially if your "min_max" was two separate numeric variable to create a report with appearance as desired.
Unless you read data in that strange format, might even be easier than starting with this summary.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.