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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: