BookmarkSubscribeRSS Feed
henryjing
Calcite | Level 5

The variable EDUCATION has values 1 2 3 4 5 6, which stand for graduate_school, university, high_school, etc.

 

I am trying to plot a standardized segment bar plot as following (picture 1), and I'm also trying to change the tick value to graduate_school, etc, which are what these value really mean. 

 

%let education_label = "graduate_school" "university" "high_school"
"others" "unknown1" "unknown2";
proc sgplot data=Freq_Education_default;
vbar EDUCATION / response = percent group=default
groupdisplay=stack;
xaxis discreteorder=data valuesdisplay =(&education_label);
yaxis grid values=(0 to 100 by 10) label="Percentage of total in group";
run;

 

However, if I change "valuesdisplay" to "values", the plot changes to picture 2, neither of two pictures is what I am aiming for. 

 

1.png

 

2.png

 

2 REPLIES 2
Reeza
Super User

Use a format, not a macro. If a level was missing the labels wouldn't align automatically, whereas they would with a format.

 

 

proc format;
value educ_fmt
1="graduate_school"
2="university"
3="high_school"
..
9 = "unknown2";
run;

Then apply the format within your proc.

 

proc sgplot data=Freq_Education_default;
vbar EDUCATION / response = percent group=default
groupdisplay=stack;

format education educ_fmt.;

xaxis discreteorder=data;
yaxis grid values=(0 to 100 by 10) label="Percentage of total in group";
run;

 

 

henryjing
Calcite | Level 5

Reeza

 

I really appreciate your help.

 

I eventually get what I want. 

 

Again, thanks so much.

 

Henry

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
  • 755 views
  • 0 likes
  • 2 in conversation