Hello everyone, I was wondering if there was a way of changing the x-axis variable to display the values we had assigned to them.
Like in this case:
PROC FORMAT; VALUE STS_NUM 0 = '<=11.19 seg' 1 = '11.2 - 13.69 seg' 2 = '13.7 - 16.69 seg' 3 = '16.7 - 60 seg' 4 = '> 60seg' ; RUN;
@sassy_seb wrote:
I did notice that in between the PROC FORMAT and the PROC SGPLOT there is a segment of code that applies formatting to the variables but I did not see anything specified.
DATA MECOG_ALL_FORMAT; SET MECOG_ALL; FORMAT FS_INT_NUM; FORMAT FP_INT_NUM; FORMAT STS_NUM; RUN;Could this possibly have anything to do with it? I find it odd that it shows for one variable out of the three specified and not the other two.
That data step removes any format assignments to the variables, if any.
I would suggest changing that data step so the desired name of the format is associated with the variable and then try running your plots after changing the plots to use the set with the formats added. Alternately, add the format statement to each plot for the variable and the desired format.
Typically most SAS procedures will make some attempt to use the custom formats by default for anything displayed. Graphs can be an exception with some custom date, time or datetime formats.
I have to assume that format shows the values you would like.
Have you assigned the format to the variable on the X axis????????????
Hint: ALWAYS provide the code you are discussing.
Sorry, it's not my code.
By assigning you mean running my proc format with the specified values for the variable? Then yes.
If I have to assign it somewhere else like on the SGPLOT then no, I don't think so.
PROC FORMAT; VALUE FS_INT_NUM 0 = 'Vigoroso' 1 = 'Vulnerable' 2 = 'Leve' 3 = 'Moderado' 4 = 'Severo' ; VALUE FP_INT_NUM 0 = 'Vigoroso' 1 = 'Fragil' 2 = 'Pre fragil' ; VALUE STS_NUM 0 = '<=11.19 seg' 1 = '11.2 - 13.69 seg' 2 = '13.7 - 16.69 seg' 3 = '16.7 - 60 seg' 4 = '> 60seg' ; RUN;
PROC SGPLOT DATA=MECOG_ALL; VLINE ME_SARINTERPRET / RESPONSE=MMSE_SCORING STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL; VLINE ME_SARINTERPRET / RESPONSE= LETRA_F STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL; VLINE ME_SARINTERPRET / RESPONSE= LETRA_A STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL; VLINE ME_SARINTERPRET / RESPONSE= SIMBOLO STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL; VLINE FP_INT / RESPONSE=MMSE_SCORING STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL; VLINE FP_INT / RESPONSE= LETRA_F STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL; VLINE FP_INT / RESPONSE= LETRA_A STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL; VLINE FP_INT / RESPONSE= SIMBOLO STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL_FORMAT; VLINE FS_INT_NUM / RESPONSE=MMSE_SCORING STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL_FORMAT; VLINE FS_INT_NUM / RESPONSE= LETRA_F STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL_FORMAT; VLINE FS_INT_NUM / RESPONSE= LETRA_A STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL_FORMAT; VLINE FS_INT_NUM / RESPONSE= SIMBOLO STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL_FORMAT; VLINE STS_NUM / RESPONSE=MMSE_SCORING STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL_FORMAT; VLINE STS_NUM / RESPONSE= LETRA_F STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL_FORMAT; VLINE STS_NUM / RESPONSE= LETRA_A STAT=MEAN MARKERS GROUP=PID_PREF; RUN; PROC SGPLOT DATA=MECOG_ALL_FORMAT; VLINE STS_NUM / RESPONSE= SIMBOLO STAT=MEAN MARKERS GROUP=PID_PREF; RUN;
The code has a PROC FORMAT assigning the values, and then various plots. Running this I can see that the values for FP_INT_NUM do get output in the results viewer. I noticed that that one is plotting the data MECOG_ALL instead of MECOG_ALL_FORMAT. I tried running an instance of MECOG_ALL with the values I am trying to change, like FS_INT_NUM and STS_NUM but instead of getting the values I just got the same but in decimal notation. So 0 became 0.00 etc.
I did notice that in between the PROC FORMAT and the PROC SGPLOT there is a segment of code that applies formatting to the variables but I did not see anything specified.
DATA MECOG_ALL_FORMAT; SET MECOG_ALL; FORMAT FS_INT_NUM; FORMAT FP_INT_NUM; FORMAT STS_NUM; RUN;
Could this possibly have anything to do with it? I find it odd that it shows for one variable out of the three specified and not the other two.
The one that displays the values:
Other two:
@sassy_seb wrote:
I did notice that in between the PROC FORMAT and the PROC SGPLOT there is a segment of code that applies formatting to the variables but I did not see anything specified.
DATA MECOG_ALL_FORMAT; SET MECOG_ALL; FORMAT FS_INT_NUM; FORMAT FP_INT_NUM; FORMAT STS_NUM; RUN;Could this possibly have anything to do with it? I find it odd that it shows for one variable out of the three specified and not the other two.
That data step removes any format assignments to the variables, if any.
I would suggest changing that data step so the desired name of the format is associated with the variable and then try running your plots after changing the plots to use the set with the formats added. Alternately, add the format statement to each plot for the variable and the desired format.
Typically most SAS procedures will make some attempt to use the custom formats by default for anything displayed. Graphs can be an exception with some custom date, time or datetime formats.
PROC FORMAT;
VALUE STS_NUM
0 = '<=11.19 seg'
1 = '11.2 - 13.69 seg'
2 = '13.7 - 16.69 seg'
3 = '16.7 - 60 seg'
4 = '> 60seg'
;
RUN;
data have;
call streaminit(42);
do x=0 to 4;
y = rand("uniform",10,20);
output;
end;
run;
proc SGPLOT data=have;
series x=x y=y;
xaxis VALUESFORMAT=STS_NUM.;
yaxis min=0 max=20;
run;
[EDIT:]
Forgot about the picture 🙂
Thank you! How can I do that to a vertical line chart? Or can I still use the VALUESFORMAT?
PROC FORMAT;
VALUE STS_NUM
0 = '<=11.19 seg'
1 = '11.2 - 13.69 seg'
2 = '13.7 - 16.69 seg'
3 = '16.7 - 60 seg'
4 = '> 60seg'
other = " "
;
RUN;
data have;
call streaminit(42);
do group = "A","B","C";
do x=0 to 4;
y = rand("uniform",10,20);
output;
end;
end;
run;
ods graphics / width=600px;
proc SGPLOT data=have;
series x=y y=x / group=group;
yaxis VALUESFORMAT=STS_NUM.;
xaxis min=10 max=20;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.