DATA Step, Macro, Functions and more

appending data sets with different date formats - solved

Reply
N/A
Posts: 0

appending data sets with different date formats - solved

My ultimate goal is to append 2 data sets. The base data set has 2 dates that have the format datetime22.3 These dates look like 01OCT2007:00:00:00:000
The data set to be appended has the same date fields but they are formatted as $24. They look like this: 2007/11/01:12:00:00 AM

All column names in both tables are the same, but some differ in length and type. When I use proc append with force, the dates that come from the second data set are missing after the append.

I have tried this:
Admission_date = put(input(txtAdmission_date,AnyDtDTm11.), datetime22.3);
This gives me 01NOV2007:00:00:00:000, but the format is still $22 rather than datetime22.3

The original table was pulled from a SQL server data base using proc sql. The second table was imported from a .csv file into a dataset.

Thanks for any help.

Message was edited by: pk

Message was edited by: pk Message was edited by: pk
Super Contributor
Super Contributor
Posts: 3,174

Re: appending data sets with different date formats

Your objective here should be to have SAS DATETIME variables (not DATE variables for clarification), as explained in your post. Consider that SAS stores DATETIME type variables as numeric representing seconds since 01JAN1960:00:00:00. A SAS DATE variable, a SAS numeric variable as well, represents days since 01JAN1960.

So, you should not want to do a PUT at all, with your conversion code, only the INPUT to convert the character string to a SAS DATETIME numeric variable value. Instead, perform your INPUT function, and also assign a SAS DATETIME FORMAT statement to the variable you are converting from character-format to numeric.

Have a look at the SAS DOCUMENTATION on the SAS support website, where the topic about SAS DATE and DATETIME variables is discussed extensively -- URL link is http://support.sas.com/ for reference.

Scott Barry
SBBWorks,Inc.
N/A
Posts: 0

Re: appending data sets with different date formats

Thanks for the help. That did it.
Ask a Question
Discussion stats
  • 2 replies
  • 263 views
  • 0 likes
  • 2 in conversation