Hi,
In my file I have date written in this form (20131126). I want to keep only year and month(201311)
I tried the following
Data want;
set have;
Format date yymmn; (not my variable name is date)
run;
This code is not working. I am not getting the desired result. Please help.
@abdulla wrote:
No, it doesn't work. I got 2.01E7. Also I am continuously getting the following msg.
ERROR: There was a problem with the format so BEST. was used.
If your value is printing as 2.01E7 then it is neither a date (number of days since 1960) or a datetime (number of seconds since 1960).
269 data test; 270 x= 2.01E7 ; 271 put 'COMMA15. ' @13 x comma15. ; 272 put 'DATE9. ' @13 x date9. ; 273 put 'DATETIME20. ' @13 x datetime20. ; 274 run; COMMA15. 20,100,000 DATE9. ********* DATETIME20. 20AUG1960:15:20:00
Looks like you might have stored you dates as numbers where the tens and ones place represent the day of the month, etc.
To convert them into actual dates use could use an INPUT() function. You will first need to convert them into a string.
data want ;
set have;
date = input(put(date,8.),yymmdd8.);
format date yymmdd10. ;
run;
Try this:
format date yymmn6.;
OK, that means your date isn't an actual SAS date, which holds a number for the days since 1 Jan 1960.
Run this test with an actual SAS date and check the log to prove it for yourself:
data test;
mydate='14may2018'd;
format mydate yymmn6.;
put _all_;
run;
Please post an example of your date data.
@abdulla wrote:
No, it doesn't work. I got 2.01E7. Also I am continuously getting the following msg.
ERROR: There was a problem with the format so BEST. was used.
If your value is printing as 2.01E7 then it is neither a date (number of days since 1960) or a datetime (number of seconds since 1960).
269 data test; 270 x= 2.01E7 ; 271 put 'COMMA15. ' @13 x comma15. ; 272 put 'DATE9. ' @13 x date9. ; 273 put 'DATETIME20. ' @13 x datetime20. ; 274 run; COMMA15. 20,100,000 DATE9. ********* DATETIME20. 20AUG1960:15:20:00
Looks like you might have stored you dates as numbers where the tens and ones place represent the day of the month, etc.
To convert them into actual dates use could use an INPUT() function. You will first need to convert them into a string.
data want ;
set have;
date = input(put(date,8.),yymmdd8.);
format date yymmdd10. ;
run;
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.