BookmarkSubscribeRSS Feed
ESwei
Fluorite | Level 6

Dear All,

 

I am a new user attempting to create a graph for a class project. The output must match the provided example:

 

My output is as follows:

:

The "State Code" in the X axis is discrepant - it appears SAS is not applying the following user defined format:

 

 

PROC FORMAT LIBRARY = HypTabs.HypFormats;
VALUE $StateCd
    ''  	  = 'Unknown'
    'IA'      = 'Iowa'
    'MS'   	  = 'Mississippi'
    'UT'      = 'Utah'
    OTHER     = 'Unexpected Value';
RUN;

Note that this format applies to the output data without issues. 

 

Any idea why this could be happening?

Thank you in advance for your assistance.

 

7 REPLIES 7
PaigeMiller
Diamond | Level 26
xaxis valuesformat=$statecd.;
yaxis valuesformat=6.4;
--
Paige Miller
ESwei
Fluorite | Level 6
Thanks for the reply and your help, unfortunately that solution did not work
PaigeMiller
Diamond | Level 26

Let me point out, for your future benefit so that you can get the help you need faster, that words like "that solution did not work" with no additional explanation never leads to anything helpful. The next question that gets asked is always: please provide more information.

 

In this case, show us the code you tried, and the output you got.

--
Paige Miller
ESwei
Fluorite | Level 6

I am sorry for my mistake.

 

Inserting the code xaxis valuesformat=$statecd. looks like this:

PROC SGPLOT DATA = Work.CrossTable;
	REFLINE 1.8 / AXIS = Y
	LINEATTRS = ( COLOR = INDIGO
	PATTERN = SHORTDASH)
	LABEL = 'National Average = 1.8'
	LABELLOC = INSIDE
	LABELPOS = MAX;
	VBAR StateCd / RESPONSE = ColPercent
	FILLATTRS = (COLOR = LIGHTSALMON)
	DATALABEL = ColPercent;
	FORMAT Colpercent 6.4;
	
	
	XAXIS
	LABEL = 'State Code'
	LABELATTRS = (WEIGHT = BOLD)
	VALUESFORMAT = $StateCd.;
	
	YAXIS VALUES = (0 TO 4 BY 1)
	GRID
	OFFSETMIN = 0
	LABEL = 'Percent'
	LABELATTRS = (WEIGHT = BOLD);
	
RUN;

The output of the graph is unchanged from previously posted.

 

ballardw
Super User

This format

PROC FORMAT LIBRARY = HypTabs.HypFormats;
VALUE $StateCd
    ''  	  = 'Unknown'
    'IA'      = 'Iowa'
    'MS'   	  = 'Mississippi'
    'UT'      = 'Utah'
    OTHER     = 'Unexpected Value';
RUN;

 

Will display a value from your data set of "IA" as "Iowa". So, which value is in your data set? That goes on the left of the = sign in the format and the value on the right is what you want to see in your output.

 

So I suspect you have define this format incorrectly at least.

mkeintz
PROC Star

I understood the OP's initial statement to mean they are getting IA, MS, and UT in the chart, but want to see Iowa, Mississippi, and Utah. @ESwei, do I understand correctly?

 

If so, then the proc format assignments should not be reversed. 

 

However, we have not been shown the log, so it may be that the program has not issued a FMTSEARCH option telling SAS to search for SGPLOT-requested formats in the HypTabs.HypFormats catalog.

 

But we can't answer that question without seeing the log and relevant code.

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ESwei
Fluorite | Level 6

Thanks for the reply and you are correct in your response - IA, MS, and UT are meant to be Iowa, Mississippi, and Utah.

I took another look at my log and it seems the issue was with the formats themselves - they output to the data set okay but attempting to apply them to the graph produced this log error:

 NOTE: PROCEDURE SGPLOT used (Total process time):
       real time           0.24 seconds
       cpu time            0.11 seconds
       
 DEBUG: Incomplete range-value definition
 DEBUG: Incomplete range-value definition
 DEBUG: Incomplete range-value definition
 NOTE: There were 3 observations read from the data set WORK.CROSSTABLE.
 

I figured this must a problem with the format itself not applying correctly so I ended up revisiting my user defined formats. It turns out the format was missing a space between ' ' for the 'Unknown' value so it wasn't applying to the graph properly. I fixed this and it worked, although I am still not sure why there were no issues with the source data set.

VALUE $StateCd
    ''  	  = 'Unknown'
    'IA'      = 'Iowa'
    'MS'   	  = 'Mississippi'
    'UT'      = 'Utah';

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 7 replies
  • 1210 views
  • 0 likes
  • 4 in conversation