BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
somebody
Lapis Lazuli | Level 10

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. .................;

 

1 ACCEPTED SOLUTION
2 REPLIES 2
gamotte
Rhodochrosite | Level 12

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;
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 22900 views
  • 5 likes
  • 3 in conversation