In my dataset, I have two similar variables filled with dates. The informat is DATETIME19. After I merge these two variables with:
DATA BCMasterSet3; SET BCMasterSet2; IF DateOfInitDx1 = "." then DateInit = put(DateOfInitDx, DATETIME19.); ELSE DateInit = DateOfInitDx1; RUN;
SAS converts the format of the new DateInit variable to $19 and outputs some of the dates correctly and others like: 1449014400
What is that? Why didn't SAS create the DateInit variable with the data type DATETIME19. like I specified? How do I fix this and make it so all dates are in DATETIME19.? Because I have tried:
Data BCMasterSetTime; SET BCMasterSet3; format DateInit DATETIME19.; RUN;
and was given the following message:
667 Data BCMasterSetTime; SET BCMasterSet3; 668 format DateInit DATETIME19.; ----------- 48 ERROR 48-59: The format $DATETIME was not found or could not be loaded. 669 RUN; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.BCMASTERSETTIME may be incomplete. When this step was stopped there were 0 observations and 87 variables. WARNING: Data set WORK.BCMASTERSETTIME was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
So, any help is appreciated. Thanks
DateInit = put(DateOfInitDx, DATETIME19.);
creates DateInit as character as PUT creates character variables when used that way. Think Print when using put.
if you want to copy a value then just use =
DateInit = DateOfInitDx;
You would use a Format or ATTRIB statement to associate the desired format.
Format DateInit datetime19.;
The error here:
668 format DateInit DATETIME19.; ----------- 48 ERROR 48-59: The format $DATETIME was not found or could not be loaded.
is because DateInit is Character. Datetime19 is a numeric format and hence cannot be applied to a character value. SAS looks for a defined character format, which would be $datetime because character variables required character formats. You likely have not run proc format to create a character format named datetime on so SAS could not find it.
And on a personal peeve note: Do not confuse DATE and DATETIME values. You have Datetimes, please call them that. Functions to manipulate dates and datetimes are different mainly because they are valued very differently. If you later ask a question like "I have a date variable and need to find the day of the week then the immediate response of MyWeekDay = Weekday(datevariable) will almost always get you an "invalid argument" note because Weekday and other date functions expect the date variable to be such. Datetime variables are counts of seconds and dates are counts of days. 1 day = 86400 so the range of values expected for the date functions blow up. I day in a datetime value will represent almost 236 years.
What is the current format and type of the variable?
And post an example of what it looks like.
DateInit = put(DateOfInitDx, DATETIME19.);
creates DateInit as character as PUT creates character variables when used that way. Think Print when using put.
if you want to copy a value then just use =
DateInit = DateOfInitDx;
You would use a Format or ATTRIB statement to associate the desired format.
Format DateInit datetime19.;
The error here:
668 format DateInit DATETIME19.; ----------- 48 ERROR 48-59: The format $DATETIME was not found or could not be loaded.
is because DateInit is Character. Datetime19 is a numeric format and hence cannot be applied to a character value. SAS looks for a defined character format, which would be $datetime because character variables required character formats. You likely have not run proc format to create a character format named datetime on so SAS could not find it.
And on a personal peeve note: Do not confuse DATE and DATETIME values. You have Datetimes, please call them that. Functions to manipulate dates and datetimes are different mainly because they are valued very differently. If you later ask a question like "I have a date variable and need to find the day of the week then the immediate response of MyWeekDay = Weekday(datevariable) will almost always get you an "invalid argument" note because Weekday and other date functions expect the date variable to be such. Datetime variables are counts of seconds and dates are counts of days. 1 day = 86400 so the range of values expected for the date functions blow up. I day in a datetime value will represent almost 236 years.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.