03-29-2018 02:58 PM
So, I have a variable named Birthmonth which has Months in Character i.e January, February...etc
I want these to be converted into their respective numeric equals.
How to do this?
03-29-2018 03:16 PM
Here are two ways:
data want; set have; select (birthmonth); when ('January') monthnum=1; when ('February') monthnum=2; when ('March') monthnum=3; when ('April') monthnum=4; when ('May') monthnum=5; when ('June') monthnum=6; when ('July') monthnum=7; when ('August') monthnum=8; when ('September') monthnum=9; when ('October') monthnum=10; when ('November') monthnum=11; when ('December') monthnum=12; otherwise; end; run; data want; set have; birthmonth='January'; array m(12) $ 15 _temporary_('January','February','March','April','May','June','July','August','September' 'October','November','December') ; monthnum = whichc(birthmonth,of m(*)); run;
Both of these are case sensitive. So if your spelling changes case such as "MAY", "May" and "may" you would want to use a case function on your variable (propcase(birthmonth) most likely) and use the appropriate comparison.
Need further help from the community? Please ask a new question.