I know you can change the lables for variables but how do I change record values?
For example, I have a variable named state and then the abbreviations for 50 states, how can I change and label them to the full name?
Ex: CA = California
There are different approaches to change the variable values, either you could try with if then else condition or simply using the format
example1: if then else
Data want;
set have;
if var='CA' then var1='California';
else if var='TX' then var1='Texas';
run;
example 2: with format, we need to create the format first and to the same variable we could apply that format with format statement.
proc format;
value $states
'CA'='California'
'TX'='Texas';
run;
data want;
set have;
format var $states.;
run;
thanks Jag,
I did this and no errors came up but it did not seem to change in the tables or dataset. Thank you for your help!
proc format;
value $states
'MA'='Massachusetts'
'CT'='Connecticut'
'NH'='New Hampshire'
'VT'='Vermont'
'ME'='Maine'
'RI'='Rhode Island';
run;
data Final;
set Final3;
format var $states.;
run;
@sconn Your code appears correct but note that a format changes how a variable is displayed but not the underlying value.
So, if it's not working, your starting point isn't necessarily what you think, IE CA isn't CA but something else.
Look at a proc contents of your dataset before and after you apply the format and try the IF version.
Post the proc contents if you need help debugging.
Check STNAME().
state=stname('NC');
put state; NORTH CAROLINA
state=stnamel('NC');
put state; North Carolina
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.