I need to turn all of my date variables to datetime in the format YYYY-MM-DD HH:MM:SS is there a quick way to do this?
data want; set have; new_variable=dhms(your_date,0,0,0); format new_variable datetime.; <--- Modify this format assigning run;
You would need to specify the missing components, for example:
data want; set have; new_variable=dhms(your_date,0,0,0); format new_variable datetime.; run;
Are there any other datetime options? This gives DDMMMYY:HH:MM:SS which isnt the one I needed.
There are plenty: Formats by Category
And if none fit your bill you can roll your own. Look at PROC FORMAT, specifically te PICTURE statement with the DATATYPE=DATETIME directive. It knows no bounds.
Hope this helps,
- Jan.
And I almost forgot: a variable is not in a specific format. It can be a numeric variable with the presentation lossely coupled. You can present your data in any format without actually modyfying the values in the table. data and presentation are separate unless you choose to store the dates as character.
- Jan.
data want; set have; new_variable=dhms(your_date,0,0,0); format new_variable datetime.; <--- Modify this format assigning run;
That's perfect thanks both.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.