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;
Here is something I did a while back that seems similiar to what you are trying to do (see attached).
Here is something I did a while back that seems similiar to what you are trying to do (see attached).
thank you very much
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
thank you
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;
Thanks a million!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.