BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nini1
Obsidian | Level 7

Hi everyone,

 

I'm trying to create the variable that will contain month and day of today date.

I tried to create it with today() function and then take month and day from today function like this:

month (today()) and day(today()). The problem is that when I create a new column with today() function there is written some number and not just a date, therefore month() and day() functions do not work. Could you please help me to solve this problem?

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You need to show more what you did.  A date IS just a number. The number of days since start of 1960. The MONTH() and DAY() functions do not care what format you are using to display the number, just that the number has the right value for a date.

2010  data test;
2011     today=date();
2012     month=month(today);
2013     day=day(today);
2014     put today=comma7. +1 today date9. +1 today yymmdd10. ;
2015     put month= day=;
2016  run;

today=22,163  05SEP2020 2020-09-05
month=9 day=5
NOTE: The data set WORK.TEST has 1 observations and 3 variables.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

You need to show more what you did.  A date IS just a number. The number of days since start of 1960. The MONTH() and DAY() functions do not care what format you are using to display the number, just that the number has the right value for a date.

2010  data test;
2011     today=date();
2012     month=month(today);
2013     day=day(today);
2014     put today=comma7. +1 today date9. +1 today yymmdd10. ;
2015     put month= day=;
2016  run;

today=22,163  05SEP2020 2020-09-05
month=9 day=5
NOTE: The data set WORK.TEST has 1 observations and 3 variables.
PaigeMiller
Diamond | Level 26

This works:

 

data want;
    thisday=today();
    thismonth=month(thisday);
    thisyear=year(thisday);
run;

Since I did this in September 2020, I get the results thismonth=9 and thisyear=2020, which are correct.

--
Paige Miller
Nini1
Obsidian | Level 7
Thank you very much

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 761 views
  • 2 likes
  • 3 in conversation