Can we use changing dates in proc format?

Accepted Solution Solved
Reply
Occasional Contributor wg
Occasional Contributor
Posts: 7
Accepted Solution

Can we use changing dates in proc format?


I just want to create a format like below, but always failed . Please let me know if it is feasible

Proc Format;

value week  today()-weekday(today())-7)    -<    today()-weekday(today())=week1

                      today()-weekday(today())-14  -<     (today()-weekday(today())-7=week2;

           run;


Accepted Solutions
Solution
‎01-30-2015 05:01 PM
Occasional Contributor
Posts: 13

Re: Can we use changing dates in proc format?

Here is something I did a while back that seems similiar to what you are trying to do (see attached).

View solution in original post

Attachment

All Replies
Solution
‎01-30-2015 05:01 PM
Occasional Contributor
Posts: 13

Re: Can we use changing dates in proc format?

Here is something I did a while back that seems similiar to what you are trying to do (see attached).

Attachment
Occasional Contributor wg
Occasional Contributor
Posts: 7

Re: Can we use changing dates in proc format?

thank you very much

Respected Advisor
Posts: 4,606

Re: Can we use changing dates in proc format?

If you don't want to have to (re)define the format on the same day that it is used, then you could use a function based format:

proc fcmp outlib=sasuser.fcmp.test;

function weekNo(d) $8;

    t = today();

    if t >= d

    then return(cats("Week",1+intck("WEEK",d,t,"CONTINUOUS")));

    else return("******");

endsub;

run;

options cmplib=sasuser.fcmp;

proc format;

value weekNo (min=5 max=8 default=5) other = [weekNo()];

run;

data _null_;

format d yymmdd10.;

do d = '15JAN2015'd to '05FEB2015'd;

    str = put(d, weekNo5.);

    put (d str) (=);

    end;

run;

d=2015-01-15 str=Week3

d=2015-01-16 str=Week3

d=2015-01-17 str=Week2

d=2015-01-18 str=Week2

d=2015-01-19 str=Week2

d=2015-01-20 str=Week2

d=2015-01-21 str=Week2

d=2015-01-22 str=Week2

d=2015-01-23 str=Week2

d=2015-01-24 str=Week1

d=2015-01-25 str=Week1

d=2015-01-26 str=Week1

d=2015-01-27 str=Week1

d=2015-01-28 str=Week1

d=2015-01-29 str=Week1

d=2015-01-30 str=Week1

d=2015-01-31 str=******

d=2015-02-01 str=******

d=2015-02-02 str=******

d=2015-02-03 str=******

d=2015-02-04 str=******

d=2015-02-05 str=******

d=2015-02-06 str=******

d=2015-02-07 str=******

d=2015-02-08 str=******

d=2015-02-09 str=******

d=2015-02-10 str=******

PG

PG
Occasional Contributor wg
Occasional Contributor
Posts: 7

Re: Can we use changing dates in proc format?

thank you

Regular Contributor
Posts: 184

Re: Can we use changing dates in proc format?

The original difficulty arises because the VALUE statement requires literals (not expressions).

But the specs change only from one launch of the program to the next (not on the fly within the program). So %sysfunc and %eval offer a workaround. Try something like this:

Proc Format;

%let td = %sysfunc( today() ) ;

%let wd = %sysfunc( weekday(&td.)) ;

value week %eval(&td.-&wd.- 7) -< %eval(&td.-&wd.   ) = week1

           %eval(&td.-&wd.-14) -< %eval(&td.-&wd.- 7) = week2 ;

%symdel td wd ;

run;

Occasional Contributor wg
Occasional Contributor
Posts: 7

Re: Can we use changing dates in proc format?

Thanks a million!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 262 views
  • 2 likes
  • 4 in conversation