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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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