I have a macro that does rolling regression. For each regression, it takes a long time so I would like to look at the LOG and know what period it is regressing. I use the function %PUT to display the period start and end. However, this displays the actual number of datetime variable without formatting. So how do I ask SAS to format and display those date variables?
My codes are :
/*Loop for years and months*/
%do yy = &year1 %to &year2;
%do mm = 1 %to 12;
/*Set date2 for mm-yy end point and date1 as 24 months prior*/
%let xmonths= %eval(12 * &nyear); *Sample period length in months;
%let date2=%sysfunc(mdy(&mm,1,&yy));
%let date2= %sysfunc (intnx(month, &date2, -1,end)); *Make the DATE2 last day of the month;
%let date1 = %sysfunc (intnx(month, &date2, -&xmonths+1, begin)); *set DATE1 as first (begin) day;
%let date3 = %sysfunc (intnx(month, &date2, 1, begin));
/*FYI --- INTNX quirk in SYSFUNC: do not use quotes with 'month' 'end' and 'begin'*/
/*An extra step to be sure the loop starts with a clean (empty) dataset for combining results*/
%put ................. Period: &date1. -------> &date2. .................;
Add %sysfunc(putn(
%put ................. Period: %sysfunc(putn(&date1.,yymmddd10.)) -------> %sysfunc(putn(&date2.,yymmddd10.)) .................;
Add %sysfunc(putn(
%put ................. Period: %sysfunc(putn(&date1.,yymmddd10.)) -------> %sysfunc(putn(&date2.,yymmddd10.)) .................;
Hello,
As you want to make computations and use data step functions, it will be easier and make the code
more readable to do so in a data step.
data _NULL_;
start_year=symgetn("year1");
end_year=symgetn("year2");
nyear=end_year-start_year+1;
xmonths=12*nyear;
do year=start_year to end_year;
do month=1 to 12;
date2=intnx('month', mdy(month,1,year), -1, 'end');
date1=intnx('month', date2, 1-xmonths, 'begin');
date3=intnx('month', date2, 1, 'begin');
put "................. Period: " date1 yymmddd10. " -------> " date2 yymmddd10. ".................";
end;
end;
run;
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.