BookmarkSubscribeRSS Feed
swimmy
Calcite | Level 5

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?

5 REPLIES 5
Sathish_jammy
Lapis Lazuli | Level 10
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;
Kurt_Bremser
Super User

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.);
swimmy
Calcite | Level 5

Screenshot 2020-11-16 100728.jpgthis is what I did (3rd row) and in the results, there is only *****. I don't know what is wrong.

ballardw
Super User

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.

 

 

Kurt_Bremser
Super User

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.

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1574 views
  • 1 like
  • 4 in conversation