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-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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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