Hi,
I am using survey data and trying to change the legend value labels highlighted in the picture below to just 'baseline' and 'midintervention'. This is tricky because they are values of the variable name: redcap_event_name and not variables themselves. I did not code these values as shown in the legend so I am not sure why they are appearing in this format. I have tried multiple codes (examples below) but continue to receive error messages and no changes in the legend. Any insight?
PROC SGPANEL DATA=base_mid;
PANELBY exp_con;
vbar chew1 / GROUP = redcap_event_name groupdisplay=cluster;
keylegend / title='Assessment' valueattrs=(baseline_arm_1= 'baseline' midintervention_6_arm_1='midintervention');
TITLE 'Health Literacy Q1J';
RUN;
PROC SGPANEL DATA=base_mid;
PANELBY exp_con;
vbar chew1 / GROUP = redcap_event_name groupdisplay=cluster legendlabel = 'baseline';
keylegend / title='Assessment';
TITLE 'Health Literacy Q1J';
RUN;
NOTE: Copyright (c) 2016 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) Proprietary Software 9.4 (TS1M5)
Licensed to MEDICAL UNIVERSITY OF SOUTH CAROLINA, Site 70085904.
NOTE: This session is executing on the X64_8HOME platform.
NOTE: Updated analytical products:
SAS/STAT 14.3
SAS/ETS 14.3
SAS/OR 14.3
SAS/IML 14.3
SAS/QC 14.3
Legend values are the values of the group variable. If the variable is character then the default format is a simple $ format and displays the text. If you want something else to appear then you either assign a custom format to the variable (doesn't require change in the data) or add a different variable with the text you want to apply (requires an additional data step).
Example with a data set you should have available.
proc sgpanel data=sashelp.cars(where=(origin in ('Europe' 'USA'))); title 'Group variable without format'; panelby origin ; vbar type/ group=drivetrain groupdisplay=cluster; run; proc format library=work; value $drivetrain 'All' = 'AWD' 'Front' = 'FWD' 'Rear' = 'RWD' ; run ; proc sgpanel data=sashelp.cars(where=(origin in ('Europe' 'USA'))); title 'Group variable with format'; panelby origin ; vbar type/ group=drivetrain groupdisplay=cluster; format drivetrain $drivetrain.; run;title;
Formats are very powerful in SAS in that you can create groups just by changing the format:
proc format library=work; value $dt 'All' = 'AWD' 'Front' ,'Rear' = '2WD' ; run ; proc sgpanel data=sashelp.cars(where=(origin in ('Europe' 'USA'))); title 'Group variable with different format'; panelby origin ; vbar type/ group=drivetrain groupdisplay=cluster; format drivetrain $dt.; run;title;
Legend values are the values of the group variable. If the variable is character then the default format is a simple $ format and displays the text. If you want something else to appear then you either assign a custom format to the variable (doesn't require change in the data) or add a different variable with the text you want to apply (requires an additional data step).
Example with a data set you should have available.
proc sgpanel data=sashelp.cars(where=(origin in ('Europe' 'USA'))); title 'Group variable without format'; panelby origin ; vbar type/ group=drivetrain groupdisplay=cluster; run; proc format library=work; value $drivetrain 'All' = 'AWD' 'Front' = 'FWD' 'Rear' = 'RWD' ; run ; proc sgpanel data=sashelp.cars(where=(origin in ('Europe' 'USA'))); title 'Group variable with format'; panelby origin ; vbar type/ group=drivetrain groupdisplay=cluster; format drivetrain $drivetrain.; run;title;
Formats are very powerful in SAS in that you can create groups just by changing the format:
proc format library=work; value $dt 'All' = 'AWD' 'Front' ,'Rear' = '2WD' ; run ; proc sgpanel data=sashelp.cars(where=(origin in ('Europe' 'USA'))); title 'Group variable with different format'; panelby origin ; vbar type/ group=drivetrain groupdisplay=cluster; format drivetrain $dt.; run;title;
Thank you so much! Your coding of 'Group variable with format' worked:
Proc format library=work;
value $redcap_event_name
'baseline_arm_1' = 'Baseline'
'midintervention_6_arm_1' = 'Midintervention';
run;
PROC SGPANEL DATA=base_mid;
PANELBY exp_con;
vbar chew1 / GROUP = redcap_event_name groupdisplay=cluster;
format redcap_event_name $redcap_event_name.;
keylegend / title='Assessment';
TITLE 'Health Literacy Q1J';
RUN;
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.
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.