Hi, I need to create a new variable by extracting the day of the week (sunday to saturday) out of a datetime16. (DDMMMYY:00:00:00). Can somebody help me out?
data have;
Date1 = '17mar85'd;
Word_day = put(Date1,DOWNAME.);
format Date1 datetime16.;
run;
I hope this will help you to get the expected result.
data want; set have; Word_day = put(Date_Column,DOWNAME.); run;
It is always a good thing to provide data in usable form (a data step with datalines), so we have a clear picture what you're talking about.
DOWNAME expects a date value as argument. In SAS, dates and datetimes work on a different scale (count of days vs. count of seconds), so if you do have a SAS datetime, you need to extract the date with DATEPART first:
newvar = put(datepart(oldvar),downame.);
this is what I did (3rd row) and in the results, there is only *****. I don't know what is wrong.
Depending on how you are examining the data you have likely issues.
If the display width of a column in a table viewer is not wide enough then SAS will typically display *** until the column is made wide enough.
A second, and related issue, is that the "date" is treated as having a year past 9999 and none of the SAS display formats work with dates that far in the future.
A third possibility is if the variable JOUR already exists in your data then the format assigned to the JOUR variable does not like the value of putting the datepart.
I see no start_date in that screenshot.
Please post data in usable form (I will NOT repeat that request for a third time),
and post the complete log of your data step by copy/pasting it into a window opened with the </> button. Do not, I repeat NOT, post logs or code in pictures.
Use the "little running man" button right next to the </> for code.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.