pickdate.sas
/* Richard A. DeVenezia
* http://www.devenezia.com
* 10/18/03
*
* Interactive date selection
*
* Place an M, Q, or Y in the <<< or >>> field
* and press F3:
* - advance or decline towards directed month, quarter or year
*
* Change the value of a date (i.e. put an x in the field)
* and press F3:
* - select the date
*/
%macro pickdate(date=, BG=white);
%local i j n date days first ulday month year selected BG;
%do i = 1 %to 42;
%local date&i dom&i dom_&i;
%end;
%do i = 1 %to 6;
%local week&i;
%end;
%if %length(&date) = 0 %then
%let date = %sysfunc (today());
%let n=0;
%do i = 1 %to 6;
%let week&i =;
%do j = 1 %to 7;
%let n = %eval (&n+1);
%let week&i=&&week&i " " c=&BG a=rev_video
dom&n 3 c=black " " ;
%end;
%end;
%let window =
PickDate rows=18 columns=50 color=&BG
#3 @12 prev a=underline
+2 month 9 protect=yes
+1 year 4 protect=yes
+2 next a=underline
/ @3 "&days"
/ @4 &week1
/ @4 &week2
/ @4 &week3
/ @4 &week4
/ @4 &week5
/ @4 &week6
;
%window &window;
%pickDate:
%let month = %sysfunc (putn(&date, monname));
%let year = %sysfunc (year(&date));
%let days = Sun Mon Tue Wed Thu Fri Sat;
%let first = %sysfunc (intnx(month, &date, 0));
%let uldate = %eval (&first - %sysfunc (weekday(&first)) + 1);
%if &uldate = &first %then
%let uldate = %eval (&uldate - 7);
%let n=0;
%let date=&uldate;
%do i = 1 %to 6;
%let week&i =;
%do j = 1 %to 7;
%let n = %eval (&n+1);
%let date&n = &date;
%let dom&n = %quote(%left(%sysfunc (day(&date),2.)));
%let dom_&n = &&dom&n;
%let date = %eval (&date+1);
%end;
%end;
%let prev = <<<;
%let next = >>>;
%display PickDate;
%let prev = %upcase(%substr(%sysfunc(compress(&prev,<))%str( ),1,1));
%let next = %upcase(%substr(%sysfunc(compress(&next,>))%str( ),1,1));
%if &prev = M %then %do;
%let date = %sysfunc (intnx (month, &first, -1));
%goto pickDate;
%end;
%if &prev = Q %then %do;
%let date = %sysfunc (intnx (quarter, &first, -1));
%goto pickDate;
%end;
%if &prev = Y %then %do;
%let date = %sysfunc (intnx (year, &first, -1));
%goto pickDate;
%end;
%if &next = M %then %do;
%let date = %sysfunc (intnx (month, &first, 1));
%goto pickDate;
%end;
%if &next = Q %then %do;
%let date = %sysfunc (intnx (quarter, &first, 1));
%goto pickDate;
%end;
%if &next = Y %then %do;
%let date = %sysfunc (intnx (year, &first, 1));
%goto pickDate;
%end;
%do i = 1 %to 42;
%if &&dom_&i ne &&dom&i %then
%let selected = "%sysfunc(putn(&&date&i,date9))"D;
%end;
%if %length (&selected) %then &selected;
%mend;
/*;
%put %pickDate;
%*put %pickDate(BG=gray);
*/;