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

Hello all,

I am getting "invalid argument" error to both the MONTH() function and YEAR() function, but I am confused because I don't see why the argument is invalid. The variable is "month_date" and here are two example observations:

month_date
31Jul2010 0:00:00
31Jul2010 0:00:00

in SAS column properties the data format is listed as "DATETIME20." -- Why is this not a valid format for these functions which state in their documentation that they accept datetime variables? I must be missing something here..

-Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

When a SAS variable month_date is actually date/time values, then the following code does not work

month(month_date)

However, the following code should work

month(datepart(month_date))

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

When a SAS variable month_date is actually date/time values, then the following code does not work

month(month_date)

However, the following code should work

month(datepart(month_date))

--
Paige Miller
AllSoEasy
Obsidian | Level 7

Excellent, easy enough. Thank you!

Vince28_Statcan
Quartz | Level 8


I don't see anywhere in MONTH and YEAR documentation that it accepts datetime variables. It only mentions it accepts date variables. As pointed out by Paige, datepart(datetimevariable) is the way to output a date out of a datetime and should fix your issue.

There is a clear distinction between dates (number of days since 01JAN1960) and datetimes (number of seconds since 01JAN1960).

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 4817 views
  • 3 likes
  • 3 in conversation