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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.