I am trying to use SAS code in order to interpret a data set, but have ran into this error message:
Character variables need character formats. Character format names always start with a $ character.
What are the raw values stored in _IMPCTY, and how is the _IMPCTY format defined in PROC FORMAT?
The raw values stored in _IMPCTY are county names, while the IMPCTY is defined in PROC FORMAT as:
FORMAT _IMPCTY _IMPCTY.;
this is the entire last statement in the code:
proc surveyfreq data=b2021 nomcar; /*Adult current smoking by county*/
strata _ststr;
weight _llcpwt_trimmed_county; *use county weight;
tables _IMPCTY*_rfsmok3/ row cl;
FORMAT _IMPCTY _IMPCTY.;
run;
Format names used with character variables must start with a $ as in $_IMPCTY. . If the value of the variable is numeric then the format name cannot start with $.
I believe you were asked to provide the Proc Format code defining the format. That would start with the statement Proc Format and remove any question about the definition of the Format.
It would not be the first time that a data source upstream from existing analysis code changed a variable type. If you are using code that someone else wrote they may have had a numeric variable, such as a county number and the format would then display the name of the county for output. But if the data source changed so that your County variable is now text then that format, if defined for numeric values, is not valid for use with your variable _IMPCTY. If you have character values it is very likely that you do not even need or want the format.
Run your code without the format and see if the results are as expected:
proc surveyfreq data=b2021 nomcar; /*Adult current smoking by county*/ strata _ststr; weight _llcpwt_trimmed_county; *use county weight; tables _IMPCTY*_rfsmok3/ row cl; run;
What should the _IMPCTY format do? Please share the PROC FORMAT that creates it.
The proc format is shown below, and the _IMPCTY is the county variable in a dataset determining the smoking rates by county in a state.
proc format;
value _IMPCTY
1 = 'Albany'
3 = 'Allegany'
5 = 'Bronx'
7 = 'Broome'
9 = 'Cattaraugus'
11 = 'Cayuga'
13 = 'Chautauqua'
15 = 'Chemung'
17 = 'Chenango'
19 = 'Clinton'
21 = 'Columbia'
23 = 'Cortland'
25 = 'Delaware'
27 = 'Dutchess'
29 = 'Erie'
31 = 'Essex'
33 = 'Franklin'
35 = 'Fulton'
37 = 'Genesee'
39 = 'Greene'
41 = 'Hamilton'
43 = 'Herkimer'
45 = 'Jefferson'
47 = 'Kings'
49 = 'Lewis'
51 = 'Livingston'
53 = 'Madison'
55 = 'Monroe'
57 = 'Montgomery'
59 = 'Nassau'
61 = 'New York'
63 = 'Niagara'
65 = 'Oneida'
67 = 'Onondaga'
69 = 'Ontario'
71 = 'Orange'
73 = 'Orleans'
75 = 'Oswego'
77 = 'Otsego'
79 = 'Putnam'
81 = 'Queens'
83 = 'Rensselaer'
85 = 'Richmond'
87 = 'Rockland'
89 = 'St. Lawrence'
91 = 'Saratoga'
93 = 'Schenectady'
95 = 'Schoharie'
97 = 'Schuyler'
So you can clearly see that this format is meant to display numbers as county names. You can only apply it to numeric, but not character variables.
If the character variable already contains county names, the format is not needed.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.