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!
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.
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.
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;
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,
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!
Ready to level-up your skills? Choose your own adventure.