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

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;

SGPlot1.pngSGPlot2.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

 

Dave25
Quartz | Level 8
nice teaching example - thank you!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 550 views
  • 0 likes
  • 2 in conversation