When I run the code, below, WITHOUT the format, I get the values on the x-axis.
I want to suppress every-other-year values (and the values at 1999, 2001, and 2008), so I'm trying to use the format to set these values to blank – when I use the format, it suppresses the values I was hoping to suppress, but the values I expect to see are now an "*" instead of the values
(the variable PCT1, with a value for only year 2000, was created so I don't get a connected line with the values for years 2009 through 2019)
data test;
input YEAR PCT PCT1;
cards;
2000 . 90
2009 71 .
2010 70 .
2011 68 .
2012 67 .
2013 64 .
2014 62 .
2015 61 .
2016 58 .
2017 55 .
2018 52 .
2019 51 .
;
run;
proc format;
value y1fmt
1999 = ' '
2001 = ' '
2008 = ' '
2010 = ' '
2012 = ' '
2014 = ' '
2016 = ' '
2018 = ' ' ;
run;
proc sgplot data=test; *format year y1fmt.;
series y = PCT x = year / markers;
scatter y = PCT1 x = year;
xaxis integer fitpolicy=none ranges=(1999-2001 2008-2019);
run;
Try this format definition:
proc format; value y1fmt (default=4) 1999 = ' ' 2001 = ' ' 2008 = ' ' 2010 = ' ' 2012 = ' ' 2014 = ' ' 2016 = ' ' 2018 = ' ' ; run;
Learning point: SAS will display * whenever you attempt to display more "value" then the format is defined to display.
The way you defined the format SAS thought the values displayed should only occupy one character. So when you try to show 2017 it will not fit in the one space.
Alternately you could use an explicit definition for all other values such as:
proc format; value y1fmt 1999 = ' ' 2001 = ' ' 2008 = ' ' 2010 = ' ' 2012 = ' ' 2014 = ' ' 2016 = ' ' 2018 = ' ' other = [F4.0] ; run;
Since this provides a specific format for the other values then they display.
Note the way to reference another format as part of a definition uses [ ] around the other format name.
Try this format definition:
proc format; value y1fmt (default=4) 1999 = ' ' 2001 = ' ' 2008 = ' ' 2010 = ' ' 2012 = ' ' 2014 = ' ' 2016 = ' ' 2018 = ' ' ; run;
Learning point: SAS will display * whenever you attempt to display more "value" then the format is defined to display.
The way you defined the format SAS thought the values displayed should only occupy one character. So when you try to show 2017 it will not fit in the one space.
Alternately you could use an explicit definition for all other values such as:
proc format; value y1fmt 1999 = ' ' 2001 = ' ' 2008 = ' ' 2010 = ' ' 2012 = ' ' 2014 = ' ' 2016 = ' ' 2018 = ' ' other = [F4.0] ; run;
Since this provides a specific format for the other values then they display.
Note the way to reference another format as part of a definition uses [ ] around the other format name.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.