BookmarkSubscribeRSS Feed
TomS1
Calcite | Level 5

I am trying to display tick mark values on a log scale x-axis from 0.1 to 10000 where the 1000 and 10000 values are displayed with commas. Ideally I'd like the values displayed to be 0.1, 1, 10, 100, 1,000, and 10,000. I can adjust the value format in the xaxis statement to comma8.1, but this adds a decimal place to all the values (0.1, 1.0, 10.0, 100.0, 1,000.0, and 10,000.0). If I use a comma8. format the 0.1 value is displayed as 0 (0, 1, 10, 100, 1,000, and 10,000). See below my base code to generate the figures and the formats used to try and display commas. I'm using SAS 9.4 (TS1M5).

 

- No value formatting:

proc sgplot data=Serum noautolegend noborder;
where PFAS="PFOS" and Home="A" and Participant=1 and Ave_Water_Conc>0;
scatter x=Serum_Level y=PFAS/ markerattrs=(symbol=CircleFilled color=CX9c5596/*CX5e3c99*/ size=18);
refline 2273.1 / axis=x lineattrs=(color=white thickness=0) label="Your result:_2273 ug/L" splitchar="_" splitjustify=center
labelattrs=(family=calibri size=11 color=CX9c5596/*CX5e3c99*/ weight=bold) LABELLOC=outside LABELPOS=max;
refline 14.6 / axis=x lineattrs=(pattern=solid color=CX5c98ca/*CXfdb863*/ thickness=5); /*"U.S._95%tile, total population, 2017-2018"*/
refline 23.5 / axis=x lineattrs=(pattern=solid color=CX86afb3/*CXb2abd2*/ thickness=5); /*"C8_study, Little Hocking OH, median, PFAS exchange"*/
refline 240 / axis=x lineattrs=(pattern=solid color=CX3e756d/*CXe66101*/ thickness=5); /*"Ronneby_study, GM, female, 61-70 yrs, Xu et al. Serum 2021"*/
xaxis type=log logstyle=logexpand logbase=10 values=(0.1 1 10 100 1000 10000) minor /*display=(nolabel)*/
label="Concentration (ug/L)" labelattrs=(family=calibri size=11) valueattrs=(family=Calibri size=11);
yaxis labelattrs=(family=calibri size=11) valueattrs=(family=calibri size=11) display=(nolabel noline novalues noticks);
run;

TomS1_2-1661200173535.png

 

 

- With valuesformat=Comma8.1:

TomS1_3-1661200349501.png

 

 

- With valuesformat=Comma8.:

TomS1_4-1661200423693.png

 

Any help would be greatly appreciated. Thank you.

3 REPLIES 3
ballardw
Super User

When the problem is a format then sometimes a custom format is your answer.

Try adding this to your code to make a format available:

proc format;
value mylogaxis
0.1 -< 1 = [F3.1]
1   -< 1000= [f3.0]
1000-high  = [Comma8.0]
;
run;

and use Valuesformat=mylogaxis.

 

TomS1
Calcite | Level 5

Thank you ballardw. Using proc format did the trick. I adjusted the code slightly and then used a separate format statement. Worked brilliantly. Thanks again. 

 

proc format;
value logaxis
0.1 = [3.1]
1 = [3.0]
10 = [3.0]
100 = [3.0]
1000 = [comma8.0]
10000 = [comma8.0];
run;

 

/*PFOS*/
proc sgplot data=Serum noautolegend noborder;
where PFAS="PFOS" and Home="A" and Participant=1 and Ave_Water_Conc>0;
scatter x=Serum_Level y=PFAS/ markerattrs=(symbol=CircleFilled color=CX9c5596/*CX5e3c99*/ size=18);
refline 2273.1 / axis=x lineattrs=(color=white thickness=0) label="Your result:_2273 ug/L" splitchar="_" splitjustify=center
labelattrs=(family=calibri size=11 color=CX9c5596/*CX5e3c99*/ weight=bold) LABELLOC=outside LABELPOS=max;
refline 14.6 / axis=x lineattrs=(pattern=solid color=CX5c98ca/*CXfdb863*/ thickness=5); /*"U.S._95%tile, total population, 2017-2018"*/
refline 23.5 / axis=x lineattrs=(pattern=solid color=CX86afb3/*CXb2abd2*/ thickness=5); /*"C8_study, Little Hocking OH, median, PFAS exchange"*/
refline 240 / axis=x lineattrs=(pattern=solid color=CX3e756d/*CXe66101*/ thickness=5); /*"Ronneby_study, GM, female, 61-70 yrs, Xu et al. Serum 2021"*/
xaxis type=log logstyle=logexpand logbase=10 values=(0.1 1 10 100 1000 10000) /*valuesformat=logaxis*/ minor /*display=(nolabel)*/
label="Concentration (ug/L)" labelattrs=(family=calibri size=11) valueattrs=(family=Calibri size=11);
format Serum_level logaxis.;
yaxis labelattrs=(family=calibri size=11) valueattrs=(family=calibri size=11) display=(nolabel noline novalues noticks);
run;

 

TomS1_0-1661215982894.png

 

ballardw
Super User

Just be aware that if you use any other values= that lists another value to display, such as 50 or 500 or 5000 that will revert back to the default display rules since none of those are in your format definition.

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 817 views
  • 0 likes
  • 2 in conversation