04-12-2018 10:35 AM - edited 04-12-2018 10:40 AM
I have two data sets I want to merge based on a variable sas_dt. Both were imported from CSV files at one point.
On the first dataset the variable sas_dt has the column attributes Format - BEST12., informat 12., numeric, and if you look at the table in the library it lists sas_dt as an integer, that is ultimately the number of seconds.
On the other dataset the variable sas_dt has the column attributes Format - datetime16. Informat 16., numeric, and if you look at the table in the library it lists sas_dt formated as the date.
When I print
format sas_dt datetime.;
Example of the integer I want to use as a commonality between all tables would look like be 1820225812, 18202225813, etc.
They list the same dates and times.
I need to merge these datasets, but this seems to be the hangup. I also wish to work with the integer format.
How to I convert sas_dt to the integer format so that it is stored in my library as an integer (i.e. I click on the table and it is displayed/stored as an integer)?
And just for the sake of asking, how do I convert an integer so it is stored in my library as a datetime (i.e. I click on the table and it is displayed/stored as a date and time)?
04-12-2018 10:47 AM
Is the variable a numeric or is it a date? Makes no sense if you have a date variable to "convert it to numeric", convert it to a date<time>. If its just a numeric, don't call it a date.
04-12-2018 10:50 AM
Those are the column attribute designations when you right click on the column when the table is open.
Lists it as numeric, displays it as a date.
This seems to be a recent thing because whenever I've used datetime. in the past it has always been an integer.
At any rate, the problem is solved well enough for now. If there is a more elegant solution, I'd be happy to hear it.
04-12-2018 11:10 AM - edited 04-12-2018 11:12 AM
If they are both numeric (date, time and datetime values are numbers) then there is no need to convert anything. Just make sure to apply the format you want in the resulting merged dataset so that humans can understand the values when they are printed.
data want ; merge not_formatted formatted ; by sas_dt ; format sas_dt datetime20. ; run;