$UPCASE1. format?
data have;
input string $20.;
cards;
married
Married
Marrie
M
;
run;
proc print data=have;
var string;
format string $upcase1.;
run;
How about an INFORMAT to read the data with?
The Invalue used to create an informat has the option of upcase which converts all text to upper case before comparing to the list of values. The other=_error_ option means that any values encountered that you didn't expect generate and invalid data message in the log and let you know a bit sooner about such. I use that to update my informat, as needed, when my data sources are inconsistent. Such as adding Spanish spellings or their own custom abbreviation like "MAR". Which I would add to the range in my invalue.
proc format; invalue $status (upcase) 'MARRIED'='M' 'SINGLE' ='S' 'WIDOWED'='W' 'DIVORCED'='D'
' '= ' '
other=_error_ ; run; data example; input status $status10.; datalines; Married married marrieD singLE wIDOWED divorced
newvalue ;
Optionally use this to assign a NUMERIC code value so you have a pretty constant order and use another custom format to display the meaning of the code.
This type of informat can also be used to recode values into either a new variable or (dangerous) the same.
codedstatus = input(status,$status.);
Here is another option if you don't mind creating a new variable:
data test;
input string $;
cards;
married
Married
MARRIED
;
run;
proc format;
value $stat "MARRIED"='M';
run;
data test;
set test;
string1=put(upcase(string),$stat.);
run;
proc print;
run;
Why not just read the data using the $UPCASE informat. Then the stored value will be consistent and it will be easier to create a format to display the values. If those are the only values you could use $1. as the format to display just the first letter.
If you want more control make a custom informat and/or a custom format. I custom informat could use the UPCASE option to convert the source to upcase in addition to encoding the values.
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!
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.