BookmarkSubscribeRSS Feed
Len18
Fluorite | Level 6
%MACRO DATA(beg, end, beg_1, end_1);
%LOCAL start start1 i j prvmth dt;
%let start=%sysfunc(inputn(&beg,yymmn6));
%let start1=%sysfunc(inputn(&beg_1,yymmn6));
%do i=0 %to %sysfunc(intck(month,&start,%sysfunc(inputn(&end,yymmn6))));
%do j=0 %to %sysfunc(intck(month,&start1,%sysfunc(inputn(&end_1,yymmn6))));
%let prvmth=%sysfunc(intnx(month,&start1,&j),yymmn6);
%let dt=%sysfunc(intnx(month,&start,&i),yymmn6);



PROC SQL;
	CREATE TABLE TEST_&DT AS 
		SELECT 
            PROD,
			CASE WHEN PROD IN (SELECT PROD FROM TEST2_&PRVMTH.)
				THEN 'OLD' 
				ELSE 'NEW' 
			END AS NEW 
		FROM IND_&DT							 
QUIT;

%END;
%END;
%MEND;


%let dt = %sysfunc( intnx( month, &todaysdate, -1, e), yymmn6. ); *TO CALC END OF 13MTH REPORTING PERIOD;
%put dt is &dt;

%let prevdt = %sysfunc( intnx( month, &todaysdate, -13, e), yymmn6. ); *TO CALC START OF 13MTH REPORTING PERIOD;
%put prevdt is &prevdt;

%let prvmth = %sysfunc( intnx( month, &todaysdate, -2, e), yymmn6. ); *TO CALC MTH PRIOR TO CURRENT MTH OF CURRENT YR;
%put prvmth is &prvmth;

%let prevyrmth = %sysfunc( intnx( month, &todaysdate, -14, e), yymmn6. ); *TO CALC MTH PRIOR TO START OF 13 MTH REPORTING;
%put prevyrmth is &prevyrmth;



%DATA(&PREVDT,&DT,&PREVYRMTH,&PRVMTH);


Len18
Fluorite | Level 6
Actually, I just changed the name of the field created by the case when statement and that fixed it. Phew! Thanks!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 17 replies
  • 3098 views
  • 0 likes
  • 5 in conversation