Increasing variable (while/sql)

Reply
Occasional Contributor
Posts: 14

Increasing variable (while/sql)

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

Trusted Advisor
Posts: 1,203

Re: Increasing variable (while/sql)

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;

Grand Advisor
Posts: 17,325

Re: Increasing variable (while/sql)

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.

Occasional Contributor
Posts: 14

Re: Increasing variable (while/sql)

i need to compare with some holidays on my holiday_table

Grand Advisor
Posts: 17,325

Re: Increasing variable (while/sql)

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

Generating Holiday Lists - sasCommunity

Occasional Contributor
Posts: 14

Re: Increasing variable (while/sql)

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?

Grand Advisor
Posts: 17,325

Re: Increasing variable (while/sql)

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.

Ask a Question
Discussion stats
  • 6 replies
  • 207 views
  • 10 likes
  • 3 in conversation