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

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.

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
  • 6 replies
  • 622 views
  • 10 likes
  • 3 in conversation