BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sms39
Fluorite | Level 6

Hi all,

 

I am trying to create a pie chart with the ages of a group of study participants, but am struggling to divide the data points into specific categories within the chart. I would like to divide the group into ages <30, 30-59, and >59, but can't seem to group the data points into these 3 categories when I produce the pie chart. Is there a way to specify these groups in the proc template code, or do I need to create groups in the data set before trying to make the chart?

 

thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

 

 

proc sgrender template=SASStudio.Pie data=DataSet;

format Screening_age age_grp. ;


run;

 

if the format isn't permanently associated with the variable.

View solution in original post

5 REPLIES 5
Reeza
Super User

Use a FORMAT in the code. If the data is grouped by the format it should work but it may also depend on which PROC you're using, which you haven't specified.

 


@sms39 wrote:

Hi all,

 

I am trying to create a pie chart with the ages of a group of study participants, but am struggling to divide the data points into specific categories within the chart. I would like to divide the group into ages <30, 30-59, and >59, but can't seem to group the data points into these 3 categories when I produce the pie chart. Is there a way to specify these groups in the proc template code, or do I need to create groups in the data set before trying to make the chart?

 

thank you!


 

sms39
Fluorite | Level 6

I've been able to sub-categorize the ages, but can't seem to get the pie chart to utilize the new groupings. I assume there is something I need to specify along the bolded line of code, but I can't seem to get it right. Any suggestions would be appreciated

 

/* new age groups*/
proc format;
value AgeGrp 1-30 ='<30'
value AgeGrp 30-59 = '30-59'
value AgeGrp 60-100 = '>60';
run;

proc freq data=DataSet;
format Screening_AGE AgeGrp.;
Table Screening_AGE;
Run;

 

/* Define Pie template */
proc template;
define statgraph SASStudio.Pie;
begingraph;
layout region;
piechart category= Screening_AGE /;
endlayout;
endgraph;
end;
run;

 

ods graphics / reset width=6.4in height=4.8in imagemap;

proc sgrender template=SASStudio.Pie data=DataSet;
run;

ods graphics / reset;

Reeza
Super User
You didn't actually apply the format to the SASStudio.Pie data set or at least not shown. Make sure to apply it to that data set.

One way, I don't recommend is as follows:

data sasstudio.pie;
set sasstudio.pie;
format screening_age ageGrp.;
run;

*now have proc template and SGRENDER code;
ballardw
Super User

 

 

proc sgrender template=SASStudio.Pie data=DataSet;

format Screening_age age_grp. ;


run;

 

if the format isn't permanently associated with the variable.

sms39
Fluorite | Level 6
Brilliant! Thank you so much!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 1237 views
  • 4 likes
  • 3 in conversation