Raven
Raven

Reputation: 859

Sgplot for multiple response variables

I have a dataset with over 50,000 records that looks like the following; ID, season(either high or low), bed_time and triage_time in minutes:

 ID Season Bed_time Triage_time 
 1  high    34            68
 2  low     44            20
 3  high    90            14
 4  low     71            88
 5  low     27            54

I would like to create a GROUPED VERTICAL BAR CHART where both then Bed_time Triage_time are reflected as a median and grouped by season on the X-axis:

 |   |                       |
 |   |                   |   |
 |   |    |              |   |
 |-------------------------------
     BT  TT              BT  TT
      High                 Low

I reckon I have to transpose the data and then plug into an SGPLOT, but I'm not quite sure how to do that to ensure that data can then be graphed.

 proc sgplot data=mysas.projects;
 vbar season/ stat=median 
 group=[Bed_time Triage_time] /*NEED FROM TRANSPOSED DATA*/
 groupdisplay=cluster;
 run;
 quit;

Upvotes: 1

Views: 1593

Answers (1)

Parfait
Parfait

Reputation: 107652

Indeed, you will need to reshape data from wide to long to use group call. Additionally, you will need to include a response call. Consider proc transpose for reshaping:

*** POSTED DATA
data time_data;
   length Season $ 5;
   input ID Season $ Bed_time Triage_time;   
   cards;
 1  high    34            68
 2  low     44            20
 3  high    90            14
 4  low     71            88
 5  low     27            54
;
run;

*** RESHAPE LONG TO WIDE;
proc transpose 
    data = time_data
    out = time_data_long
    name = time_group;
    by ID Season;
run;

*** CLEAN UP OUTPUT;
data time_data_long;
    set time_data_long;

    label time_group = "Time Group";
    rename col1 = value;
run;

proc sgplot data=time_data_long;
    vbar season / response=value stat=median 
    group = time_group
    groupdisplay=cluster;
run;

Plot Output

Upvotes: 1

Related Questions