BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ANKH1
Pyrite | Level 9

I have this output:

meanmin_maxmediangroup
321-4035Chef/owner
332-4531Chef's assistant
314-3928Waiter

 

With proc transpose I get this:

_NAME_COL1COL2COL3
mean323331
min_max1-402-454-39
median353128

I would like rename the COL1, COL2, COL3 in the same procedure so it can look like this:

_NAME_Chef/ownerChef's assistantWaiter
mean323331
min_max1-402-454-39
median353128

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

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

PaigeMiller
Diamond | Level 26

@ANKH1 

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.

--
Paige Miller
ANKH1
Pyrite | Level 9
Thank you for your insight. This is only a step before creating a table using proc report.
PaigeMiller
Diamond | Level 26

@ANKH1 wrote:
Thank you for your insight. This is only a step before creating a table using proc report.

Then, @ANKH1 you do NOT want to do a transpose before PROC REPORT.

--
Paige Miller
ballardw
Super User

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.

ANKH1
Pyrite | Level 9
Thank you for your insight. The min-max is a character value.

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2227 views
  • 2 likes
  • 4 in conversation