BookmarkSubscribeRSS Feed
tbatliner
Calcite | Level 5
Dear all,

how would I check e.g. "First Saturday in current Month" or "Last Sunday in current Month"? I checked [pre]intnx[/pre] but couldn't find the solution there. With something like[pre]
%if weekday(today()) = 7 and day(today()) lt 8 %then %do;
...
%end;
[/pre]
I could solve this Problem; but is there a "nicer" way?

Thanks in advance,
Thomas
8 REPLIES 8
LinusH
Tourmaline | Level 20
I think that your solution is quite neat, although the NWKDOM function may give an alternative. And to use functions with macro programming, you have to use the %sysfunc macro function.

Regards,
Linus
Data never sleeps
Patrick
Opal | Level 21
Hi Linus
What is this "NWKDOM" function? I don't know it and can't find it in the SAS OnlineDoc.
Cheers, Patrick
LinusH
Tourmaline | Level 20
It is an ETS function that has moved to Base SAS with 9.2. Sorry, should have mentioned it.

/Linus
Data never sleeps
tbatliner
Calcite | Level 5
Hi Linus,

thanks for your quick reply. Never heard of this function and as we are not using ETS I will have to use my solution.

Thanks and br,
Thomas
deleted_user
Not applicable
came across this a while ago:
http://support.sas.com/kb/24/655.html

it seems like some examples might be relevant for your needs.
tbatliner
Calcite | Level 5
Great! Never heard of "week.2" etc.
This should solve my problem in an elegant way,

thanks,
Thomas
tbatliner
Calcite | Level 5
Dear community,

exactly two years later I have a similar date-Problem: how to determine the last workday (Friday) on or before the 25th? 🐵

Let's assume I have a variable d25cm (25th of current month). I tried with
[PRE]
data _null_;
WDB25=intnx('week.6',&d25cm,(weekday(&d25cm) in (2,3,4,5,6))-1);
if today() = WDB25 then do;
/* more code */
end;
run;
[/PRE]

but that doesn't work as expected. Any idea will be of great help!

With best regards,
Thomas
tbatliner
Calcite | Level 5
I think I just found an easy solution (didn't know about the 'weekday' interval):
[PRE]
WDB25=intnx('weekday',d25cm,0);
[/PRE]

Thomas

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 8 replies
  • 2090 views
  • 0 likes
  • 4 in conversation