BookmarkSubscribeRSS Feed
Babloo
Barite | Level 11

1) I'm getting the invalid argument warning when I executed the following code and I see the value of sales_date as missing instead of '01DEC2022'd. 

 

data test;
mon_intrvl='2022-12';
sales_date = input(mon_intrvl, date9.);
run;

2) How to convert any given date value to th start date of the month? For example if input date value is  '22DEC2022' then I need the result as '01DEC2022'd. I tried the intnx function as below but it's not working.

 

data test;
start_date_edh = intnx("month",today(),"b");
run;

Warning which I got is,

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      82:40   
NOTE: Invalid numeric data, 'b' , at line 82 column 40.
start_date_edh=. _ERROR_=1 _N_=1

Any help to resolve this?

 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

If you are getting errors, show us the log.

--
Paige Miller
Tom
Super User Tom
Super User

The DATE informat needs strings in the style ddMONyyyy.  So strings like 01DEC1990 or 01-dec-1990 etc.

To read a string in the style of yyyy-mm you would need a different informat.  I think you might have to append a day of the month to get it to work.

data test;
  mon_intrvl='2022-12';
  sales_date = input(cats(mon_intrvl,'-01'), yymmdd10.);
  put sales_date=date9.;
run;

Your second mistake is you did not include the OFFSET for the INTNX() function call.  So it is trying to convert the letter B into a number.  To get the beginning of the current month use an offset of 0 months.

data test;
  start_date_edh = intnx("month",today(),0,"b");
  format start_date_edh date9.;
run;

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 161 views
  • 0 likes
  • 4 in conversation