BookmarkSubscribeRSS Feed
di_niu0
Obsidian | Level 7

Hi All, 

I've got a SAS data set like the one below. The second and third rows are the mean and median for the total fee, respectively. Similarly, the last two rows are the mean and median for the unit, respectively. This table is hard to do analysis. I would like to add some indicators to differentiate the two sets of mean and median. Not sure how to do. Thank you in advance. 

 

Variable              Value 

total_fee

mean                  100

median                110

flag_customer     1000

unit 

mean                   10

median                12

 

 

2 REPLIES 2
Reeza
Super User

Use RETAIN, please post your sample data using a data step in the future. Instructions on how to provide data in that format is included here

 

  • Retain to hold values across rows
  • LENGTH before SET to have variable in the first column rather than the last column
  • WHERE on output to filter out the missing values after the calculations are done. You could do it in another step or you can add a DELETE statement as well. 

 

data have;
infile cards truncover;
informat variable $14.;
input Variable           Value ;
cards;
total_fee
mean                  100
median                110
flag_customer     1000
unit 
mean                   10
median                12
;;;;
run;

data clean(where=(not missing(value)));
length variable_Summarized $32.;
set have;
retain Variable_Summarized;
if missing(Value) then Variable_Summarized = variable;
drop variable;
run;

proc print;
run;

@di_niu0 wrote:

Hi All, 

I've got a SAS data set like the one below. The second and third rows are the mean and median for the total fee, respectively. Similarly, the last two rows are the mean and median for the unit, respectively. This table is hard to do analysis. I would like to add some indicators to differentiate the two sets of mean and median. Not sure how to do. Thank you in advance. 

 

Variable              Value 

total_fee

mean                  100

median                110

flag_customer     1000

unit 

mean                   10

median                12

 

 


 

 

ballardw
Super User

@di_niu0 wrote:

Hi All, 

I've got a SAS data set like the one below. The second and third rows are the mean and median for the total fee, respectively. Similarly, the last two rows are the mean and median for the unit, respectively. This table is hard to do analysis. I would like to add some indicators to differentiate the two sets of mean and median. Not sure how to do. Thank you in advance. 

 

Variable              Value 

total_fee

mean                  100

median                110

flag_customer     1000

unit 

mean                   10

median                12

 

 


When you say "This table is hard to do analysis." where does it come from? If you create it as the result of one of the SAS procedures such as Proc means then syntax changes when creating it could make a big difference in how the set is made.

 

I do agree it would be hard to do analysis but I'm not sure what you actually want as indicators might not be the best way. What types of analysis do you think will be done on this data?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 532 views
  • 0 likes
  • 3 in conversation