BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lady8506
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
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.

View solution in original post

3 REPLIES 3
Reeza
Super User

What is the current format and type of the variable?

And post an example of what it looks like.

ballardw
Super User
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.

lady8506
Quartz | Level 8
This worked. Sorry I didn't get back sooner. Have been out of work due to illness =(

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1287 views
  • 2 likes
  • 3 in conversation