Hello all,
I am trying to assign value labels to a dataset so that a graph is labelled with these values.
One of my value labels is a string with two quotes within it. It doesn't actually matter to me if the quotes are double or single. The string that I want is:
"High Danger" Area
The relevant code that I've written is:
PROC FORMAT;
VALUE $VariableF
"DangerArea" = "'High Danger' Area"
run;
The value label shows up in the graph as:
'High Danger'
In other words, the last part of the value label ("Area") is truncated.
Will someone be so kind as to explain what I'm doing wrong? Thanks for your help!
"value label" is SPSS terminology. In SAS terminology only variables or dataset can have labels. To change how values are displayed you change the format that they use.
Your FORMAT definition looks valid (other than missing the closing semicolon for the VALUE statement).
You probably used the wrong WIDTH on the format. Or the graph did not have room for such a long string.
Thanks for your help, Tom.
The missing semicolon was a typo.
I can confirm that the graph does have enough room for the string, as longer strings are present and display fine. Additionally, if I change the code to:
PROC FORMAT;
VALUE $VariableF
"DangerArea" = "'High Danger Area'";
run;
Then I get:
'High Danger Area'
Your suggestion about the width being the issue is probably on the right track. I previously had a problem with many different variable names (formats) being truncated and finally realized it was because the dataset had a variable length of $16, so any names I had assigned that were more than 16 characters were being truncated. This was a confusing problem for me because the formats displayed fine when assigning the labels:
DATA LabeledDataset;
set NewDataset;
FORMAT variable $VariableF.;
RUN;
However, I noticed that the variable had a length of 16. To try and fix that issue, I included the following code before the PROC FORMAT statement:
Data NewDataset;
Length Variable $32;
Merge Dataset1 Dataset2;
run;
That fixed the truncation of all of my 16+ character labels, but the issue mentioned in the OP remains. Can you give any other hints at what might be the problem?
SAS is doing the best it can to figure out what length to use. However, you can take matters into your own hands. Replace this statement:
FORMAT variable $VariableF.;
Instead, specify the width you would like:
FORMAT variable $VariableF18.;
That should fix the problem. On a side note, you are allowed to add a width as in this example. That's the reason when you create a format you are not allowed to end the format name with a number. It gives you the flexibility to specify a width later when using the format.
Changing the LENGTH of a the variable (how much space it takes to store it) is different than changing the WIDTH of the format (how much space it takes to display it).
When you define that format you can set both a default width and a maximum width. If you don't specify either then SAS will set them both to the width of the longest display value.
Example:
proc format ;
value $gender 'M'='Male' 'F'='Female';
run;
proc freq data=sashelp.class;
tables sex / list;
format sex $gender.;
run;
proc freq data=sashelp.class;
tables sex / list;
format sex $gender4.;
run;
For more help on your graph post the actual code (or better SAS log) of what you ran. There could also be limitations of the procedure you are using that is causing the truncation so knowing exactly what you ran would help. Best would be if you could post a simple example of data and code that reproduces the problem.
Below sample prints the variable value as desired when I run it.
PROC FORMAT;
VALUE $VariableF
"DangerArea" = "'High Danger' Area"
;
run;
data have;
var='DangerArea';
run;
proc print data=have;
format var $VariableF.;
run;
Can you please execute above code and let us know if you get the same result or if the string truncation you observe also happens here for you.
If above code works for you then please share some fully working sample code that shows the issue you describe so we can replicate and investigate what's happening.
Please provide some example data and the graphics code you run, so we can recreate the issue. It might very well be that you have stumbled across a SAS bug.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.