Ok, with the explanation for @yabwon you do the conversion in data set A like this
due_date=dhms(due_date,0,0,0);
format due_date datetime19.;
More information is needed.
Is 03/01/2022 in a character variable in a data set? Is it in a numeric variable in a data set? If numeric, what is the format? Is it found in a text file that you have to read into SAS? Is it something else?
I have two seprate dates in which
Dataset A has the variable due_date = 03/01/2022- type-date length-8
Dataset B has the variable due_date = 01MAR2022:00:00:00- TYPE DATE
So I need to change the dates to same format.
Either A-B or B -A
@Akshaya_1397 wrote:
I have two seprate dates in which
Dataset A has the variable due_date = 03/01/2022- type-date length-8
Dataset B has the variable due_date = 01MAR2022:00:00:00- TYPE DATE
So I need to change the dates to same format.
Either A-B or B -A
In SAS, there is no such thing as type-date, so I don't know what you mean. Nevertheless, you have not answered my questions, so I ask again:
Is 03/01/2022 in a character variable in a data set? Is it in a numeric variable in a data set? If numeric, what is the format? Is it found in a text file that you have to read into SAS? (okay, this last one is answered, these are in SAS data sets)
The origin of the confusion is that the EG, when you hoover over variable name in open dataset, if it recognise numeric variable with date/datetime fomat it displays "date" type.
Ok, with the explanation for @yabwon you do the conversion in data set A like this
due_date=dhms(due_date,0,0,0);
format due_date datetime19.;
@Akshaya_1397 Take a look at
Working with Dates in the SAS System that's a good starting place
Here's some examples of using SAS Date/Time values
data work.have ;
date="15APR2023"d ; /* SAS Date Constant */
put date= date= ddmmyy10. ; /* Output to the SAS log the raw date value and a formated date value */
datetime="15APR2023 11:59:59"dt ; /* SAS Date Time Constant */
put datetime= datetime= datetime. ;/* Output to the SAS log the raw datetime value and a formated datetime value */
cdate=putn(date,"mmddyy8.") ; /* Convert a SAS date value into a character variable using a format (mmddyy8.) */
put cdate= ;
run ;
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.