BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
elena1234
Calcite | Level 5

Hello,

I am a newbie to SAS programming and sgplot customization. 

I will really appreciate if somebody help me with my assignements. 

Here is the first:

I have a table which contains a variable with format PERCENT7.2 and when I am trying to create a histogram (by default) the results is plot with bins: (4)%  (2)% 0% 2% 4% on the x axis. This is a problem because the values for this variable in my table are something like these: "0.26%, 0.17%, 0.25%, 0.11, 3.5%" and in this order I need  to plot on the x axis more bins and maybe between 0.05%. 

 

This is my poor attemp:

 

proc sgplot data=STPSAMP.STPEURO;
histogram growth;
density growth/ type=normal;
xaxis grid values= (-4 to 4 by 0.05);
run;

The results obviously is not what I am expecting for.

 

The second assignement:

I need to find the correlation between birth (on the x axis) and growth (on the y axis). My code  is working perfectly, but again on my y axis the values for growth variable are: (4)%  (2)% 0% 2% 4%. And in this case I need  to plot on the y axis more bins and maybe between 0.05%.

My code without customization: 

 

proc corr data=STPSAMP.STPEURO plots = scatter (nvar = all);
var birth growth;
run;

 

I've already read the SAS documentation about SGPLOT x and y statements, but nothing is working for me.

Please, help me!

Best!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If the format is indeed Percent7.2 then the value that displays as 4% is a decimal 0.04. So you need to use the DECIMAL range values in the Values option list and adjust the BY value to match.

 

xaxis grid values= (-0.04 to 0.04 by 0.005);

 

Your issue with the plots in Proc Corr are a bit different. There are not a lot of options that you can override in most of the analysis procedure plots, such as Proc Corr, as they are expected to be exploratory and nature and do not provide all of the features needed for "camera ready" report or publication plots. Often serious modifications to these plots are either better done directly from Sgplot/Sgpanel or use the ODS OUTPUT to create the plot data set used and then modify to display with SGplot or Sgpanel.

 

View solution in original post

2 REPLIES 2
ballardw
Super User

If the format is indeed Percent7.2 then the value that displays as 4% is a decimal 0.04. So you need to use the DECIMAL range values in the Values option list and adjust the BY value to match.

 

xaxis grid values= (-0.04 to 0.04 by 0.005);

 

Your issue with the plots in Proc Corr are a bit different. There are not a lot of options that you can override in most of the analysis procedure plots, such as Proc Corr, as they are expected to be exploratory and nature and do not provide all of the features needed for "camera ready" report or publication plots. Often serious modifications to these plots are either better done directly from Sgplot/Sgpanel or use the ODS OUTPUT to create the plot data set used and then modify to display with SGplot or Sgpanel.

 

elena1234
Calcite | Level 5
thank you very much!
Now my code is working perfectly for "Growth Histograms" and I understand the data type Percent7.2 thanks to you:
ods excel file='/home/u63376027/Export/Growth_Histogram.xlsx' style=seaside;
title'Growth Rate Histogram';
proc sgplot data=STPSAMP.STPEURO;
histogram growth;
density growth/ type=normal;
xaxis grid values= (-0.04 to 0.04 by 0.001);
run;
ods excel close;
 
Unfortunately my code is not working for the correlation plot with Pearson Correlation Coefficient calculation. Maybe I have a wrong sintax somewhere :((
I see you understand how the code is working,  could you please tell me where is my bug?
I will really appreciate your help.
proc corr data=STPSAMP.STPEURO plots = scatter (nvar = all);
var pop growth;
ods output = want;
run;

proc sgplot data = want;
scatter x = pop y = growth
yaxis grid values= (-0.04 to 0.04 by 0.001);
run;
Best,
Eli

 

 
 

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 Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 990 views
  • 1 like
  • 2 in conversation