Hi,
I have to create a variable which extract the month from a other existing variable, but the results does not represent reality.
DATA NEW;
set work.new;
MOIS=MONTH(DATERELEVE);
RUN;
PS: The data is imported from a xlsx files.
The MONTH() function should work fine, but it won't return a string. It will return the number of the month.
216 data test; 217 date=today(); 218 format date date9.; 219 month=month(date); 220 put date= month=; 221 run; date=08OCT2017 month=10
Perhaps you tried to attach the MONNAME. format to your new month number variable? If so then it should show JANUARY for every value since MONNAME is meant to be used with dates and the date values of 1 to 12 are all in January of 1960.
261 data _null_; 262 do month=1 to 12; 263 put month= 'date9=' month date9. ' monname=' month monname.; 264 end; 265 run; month=1 date9=02JAN1960 monname= January month=2 date9=03JAN1960 monname= January month=3 date9=04JAN1960 monname= January month=4 date9=05JAN1960 monname= January month=5 date9=06JAN1960 monname= January month=6 date9=07JAN1960 monname= January month=7 date9=08JAN1960 monname= January month=8 date9=09JAN1960 monname= January month=9 date9=10JAN1960 monname= January month=10 date9=11JAN1960 monname= January month=11 date9=12JAN1960 monname= January month=12 date9=13JAN1960 monname= January
The MONTH() function should work fine, but it won't return a string. It will return the number of the month.
216 data test; 217 date=today(); 218 format date date9.; 219 month=month(date); 220 put date= month=; 221 run; date=08OCT2017 month=10
Perhaps you tried to attach the MONNAME. format to your new month number variable? If so then it should show JANUARY for every value since MONNAME is meant to be used with dates and the date values of 1 to 12 are all in January of 1960.
261 data _null_; 262 do month=1 to 12; 263 put month= 'date9=' month date9. ' monname=' month monname.; 264 end; 265 run; month=1 date9=02JAN1960 monname= January month=2 date9=03JAN1960 monname= January month=3 date9=04JAN1960 monname= January month=4 date9=05JAN1960 monname= January month=5 date9=06JAN1960 monname= January month=6 date9=07JAN1960 monname= January month=7 date9=08JAN1960 monname= January month=8 date9=09JAN1960 monname= January month=9 date9=10JAN1960 monname= January month=10 date9=11JAN1960 monname= January month=11 date9=12JAN1960 monname= January month=12 date9=13JAN1960 monname= January
This is spot on @Tom. I bet my left arm you are correct. It also illustrates the danger to assume that some function is "not working properly". One does SAS more justice by stating that something is "not behaving as expected" which leaves some room for user error. Month() is ancient. It was in V5.08 when I started. It has gone through some proper testing by now.
If only I got a eurocent for every time a user called me to tell me that they found a bug....
Ok thanks a lot!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.