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.
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.
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.