BookmarkSubscribeRSS Feed
Krohn
Obsidian | Level 7

hi,

i'd like to increase a variable (payday) + 1 while it isn't a working day

how can i do something like that, using while and sql?

e.g:

     create table new_payday as select

          (while payday in ((select holiday from holiday_table),weekday(1),weekday(7)) then payday+1) as payday

     from old_payday;

     quit;

thanks

6 REPLIES 6
stat_sas
Ammonite | Level 13

Not sure, but I think you are trying something like this

create table new_payday as

select

case when weekday(datepart(payday))  in (1,7) then payday+1 else payday end as payday

from old_payday;

quit;

Reeza
Super User

If it was Saturday that would make the payday Sunday so that logic doesn't make sense for most businesses I know....

Look up the intnx function with the weekday option.

You can also create custom intervals to include your holidays, there's a few posts on here that cover how to do that.

Krohn
Obsidian | Level 7

i need to compare with some holidays on my holiday_table

Reeza
Super User

A bit of a long read, but worth it, the very last example is what I'm referring to:

Generating Holiday Lists - sasCommunity

Krohn
Obsidian | Level 7

tomorrow im going to test it :smileygrin:

i can only test at job.....thanks Smiley Happy

is there a way of using "while" inside proc sql?

Reeza
Super User

I think you're looking for where instead. I'm not familiar with while in SQL though it's getting rusty...

However the intervalds option methodology with customized dataset would render that requirement for this question moot.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 994 views
  • 10 likes
  • 3 in conversation