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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 799 views
  • 0 likes
  • 3 in conversation