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,
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!