BookmarkSubscribeRSS Feed
CesarOmarHR
Calcite | Level 5

Hi there

I would like to know how to group daily expenses into a by-weekly format. Since i've worked with a small database i've used the recoded function and applied ranges.

Date of ChargeBy-Weekly Expenses
16FEB201229FEB2012
01MAR201215MAR2012
19FEB201328FEB2012
04APR201315APR2013

i'll appreciate the help to construct a condition to apply in the Advanced Expression option

Thanks

César

7 REPLIES 7
Reeza
Super User

I think we need some more detail as to what you're looking to do.

One thing to look into is formats for the date variable that will automatically calculate a week portion of the date and then if you can use that to help with your calculation.

If you're looking for bi-weekly dates you could subtract or add 1 week to the result if you had an odd number for example.

CesarOmarHR
Calcite | Level 5


I basically want to fit a historical range of purchases dates into a by-weekly format. For every purchase between 01AUG2012 and 15AUG2012, label them as 15AUG2012 and the same for some other purchase between 16AUG2012 and 31AUG2012 with the label 31AUG2012.

Since i have too much data, i cannot keep creating a format within the recoded function.

Reeza
Super User

Are your bi-weekly dates custom?

I'm recommending using SAS pre-built formats so that you don't need to rebuild anything.

CesarOmarHR
Calcite | Level 5

Since i'm not that skillful yet with some unknown functions, i was given this (example) to arrange dates in a different bi-weekly format:

ifn(day(t1.purchase_date)<=15, intnx('month',t1.purchase_date,0,'e'), intnx('month',t1.purchase_date,1,'m'))

I'm trying to understand the conditions from this formula to fit my neccesities in a customized format.

Reeza
Super User

That seems to only divide it into two time periods for a month, not biweekly.

Reeza
Super User

My bi_week2 gives you biweekly counts and you can add/subtract 7 to get it closer to what you need and seems simpler.

You can refer to the docs for the definition of the intnx function, but basically it increments dates within specified intervals, in this case a biweek interval, WEEK2.

data have;

    do date="01Mar2013"d to "01Jun2013"d;

        bi_week=ifn(day(date)>=15, intnx('month',date,0,'e'), intnx('month',date,1,'m'));

        bi_week2=intnx('WEEK2', date, 0, 'BEGINNING');

        output;

    end;

    format date bi_week bi_week2 date9.;

run;

CesarOmarHR
Calcite | Level 5

Thanks i'll give it a try and let you know.

I appreciate the help

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 1890 views
  • 0 likes
  • 2 in conversation