BookmarkSubscribeRSS Feed
animesh123
Obsidian | Level 7

I want to find First day of current month, Previous month , Next month as the below code is getting an error

Data test;

date="02DEC2022"d;

Frstday=Intnx("date",date,0);

run;

 

 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

There is no "Date" value for the first argument to INTNX. You want to use the "Month" argument here.

 

Frstday=Intnx("month",date,0,'b');
--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

Try this

 

data test;
   date="02DEC2022"d;

   prevmonth = intnx('month', date, -1, 'b');
   thismonth = intnx('month', date,  0, 'b');
   nextmonth = intnx('month', date,  1, 'b');

   format prevmonth thismonth nextmonth ddmmyy10.;
run;
ballardw
Super User

The basis indicators 'B' (begin), 'E' (end), 'S' (same) are helpful

 

Data test;
  date="02DEC2022"d;
  Frstdaycurrentmonth=Intnx("month",date,0,'B');
  FrstdayPrevMonth=Intnx("month",date,-1,'B');
  FrstdayNextmonth=Intnx("month",date,1,'B');
  FrstdayThisYear = intnx('year',date,0,'B');
  LastdayThisYear = intnx('year',date,0,'E');
  FrstdayLastYear = intnx('year',date,-1,'B');
  LastdayLastYear = intnx('year',date,-1,'E');
  FrstdayNextYear = intnx('year',date,1,'B');
  LastdayNextYear = intnx('year',date,1,'E');

  SamedayPrevMonth=Intnx("month",date,-1,'S');
  SamedayNextmonth=Intnx("month",date,1,'S');
  SamedayPrevYear=Intnx("year",date,-1,'S');
  SamedayNextYear=Intnx("year",date,1,'S');

  format date frstday: lastday: Sameday: date9.;
 
run;

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
  • 4 replies
  • 10734 views
  • 1 like
  • 5 in conversation