assistance creating financial year macro variable

Reply
N/A
Posts: 1

assistance creating financial year macro variable


Hi

I am visting to create a macro variable on a accumulating financial year period, so that each month it will automatically select a date range based on the time period as we progress through the year. ie if it is Sep12 then I want to select records with a drawn date for Jul12 to Aug12, Jul11 to Aug11

or if its Feb13 then I want to select records for Jul12 to Jan13, Jul11 to Jan12.

Thanks for your help in advance. 

Occasional Contributor
Posts: 7

Re: assistance creating financial year macro variable

Here's one method:

 

%MACRO YEARDATES(SEED) ;

  /* If no value passed, assume todays date */

  %IF %STR(&SEED) eq %THEN %LET SEED = date() ;

  data _null_ ;

    do m = 1 to 12 ;

      month_start = intnx('month',&SEED,m-13,'b') ;

      month_end = intnx('month',&SEED,m-13,'e') ;

      call symput(cats('MS',m),cats("'",put(month_start,date9.),"'d")) ;

      call symput(cats('ME',m),cats("'",put(month_end ,date9.),"'d")) ;

    end ;

  run ;

  options nosymbolgen nomprint ;

  %DO M = 1 %TO 12 ;

    %PUT %NRSTR(&MS)&M resolves to &&MS&M ;

    %PUT %NRSTR(&ME)&M resolves to &&ME&M ;

  %END ;

%MEND ;

/* Then call the macro like this.... (check log afterwards) */

%YEARDATES ; /* date() as seed */

%YEARDATES('07feb2013'd) ;

Then use the appropriate macro variables in your code, e.g.

data last12months ;

  set mydata (where=(&MS1 <= date <= &ME12)) ;

run ;

Ask a Question
Discussion stats
  • 1 reply
  • 205 views
  • 0 likes
  • 2 in conversation