BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
wg
Calcite | Level 5 wg
Calcite | Level 5


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;

1 ACCEPTED SOLUTION

Accepted Solutions
Orsini
Fluorite | Level 6

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

6 REPLIES 6
Orsini
Fluorite | Level 6

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

wg
Calcite | Level 5 wg
Calcite | Level 5

thank you very much

PGStats
Opal | Level 21

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
wg
Calcite | Level 5 wg
Calcite | Level 5

thank you

Howles
Quartz | Level 8

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;

wg
Calcite | Level 5 wg
Calcite | Level 5

Thanks a million!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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