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

sassy_seb_0-1718118321492.png

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;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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.

 

 

 

 

 

 

 

View solution in original post

8 REPLIES 8
ballardw
Super User

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.

sassy_seb
Quartz | Level 8

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.

sassy_seb
Quartz | Level 8
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:

sassy_seb_0-1718120141269.png

Other two:

sassy_seb_2-1718120197499.pngsassy_seb_3-1718120223622.png

 

 

ballardw
Super User

@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.

 

 

 

 

 

 

 

sassy_seb
Quartz | Level 8

Yeah, that was it. Thanks @ballardw !

 

 

yabwon
Onyx | Level 15
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 🙂  

yabwon_0-1718119838130.png

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sassy_seb
Quartz | Level 8

Thank you! How can I do that to a vertical line chart? Or can I still use the VALUESFORMAT?

yabwon
Onyx | Level 15
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;

yabwon_0-1718121023070.png

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 8 replies
  • 1086 views
  • 5 likes
  • 3 in conversation