I have written some code, and it works just fine. I am always trying to learn other ways to do the same thing. In this case, instead of relying on PROC SQL and into: for the macro variable I would like to learn another way to accomplish this and possibly lessen the number of lines of code I am writing.
Here is what I currently have: CD=CalendarDay, PM=PriorMonth, CM=CurrentMonth
DATA DATES;
FORMAT START_DATE_PM DATE9.;
FORMAT CD3PM DATE9.;
FORMAT START_DATE_CM DATE9.;
FORMAT CD2CM DATE9.;
START_DATE_PM = INTNX('MONTH',TODAY(),-1,'B');
CD3PM = INTNX('DAY',START_DATE_PM,2);
START_DATE_CM = INTNX('MONTH',TODAY(),0,'B');
CD2CM = INTNX('DAY',START_DATE_CM,1);
RUN;
PROC SQL NOPRINT;
SELECT CD2CM, CD3PM
INTO: CD2CM,
: CD3PM
FROM DATES;
QUIT;
%PUT &CD2CM;
%PUT &CD3PM;
I'm not understanding your question. What do you want to do with the values of CD2CM & CD3PM?
If you just want to set those macro variables in a more straight forward way, you could do this.
%let START_DATE_PM = %sysfunc(INTNX(MONTH,%sysfunc(TODAY()),-1,B));
%let CD3PM %sysfunc(putn(%sysfunc(INTNX(DAY,&START_DATE_PM,2)),DATE9.));
%let START_DATE_CM = %sysfunc(INTNX(MONTH,%sysfunc(TODAY()),0,B));
%let CD2CM %sysfunc(putn(%sysfunc(INTNX(DAY,&START_DATE_CM,1)),DATE9.));
%PUT &CD2CM;
%PUT &CD3PM;
I'm not understanding your question. What do you want to do with the values of CD2CM & CD3PM?
If you just want to set those macro variables in a more straight forward way, you could do this.
%let START_DATE_PM = %sysfunc(INTNX(MONTH,%sysfunc(TODAY()),-1,B));
%let CD3PM %sysfunc(putn(%sysfunc(INTNX(DAY,&START_DATE_PM,2)),DATE9.));
%let START_DATE_CM = %sysfunc(INTNX(MONTH,%sysfunc(TODAY()),0,B));
%let CD2CM %sysfunc(putn(%sysfunc(INTNX(DAY,&START_DATE_CM,1)),DATE9.));
%PUT &CD2CM;
%PUT &CD3PM;
How about this? CALL SYMPUTX will do what you need.
DATA DATES;
FORMAT START_DATE_PM DATE9.;
FORMAT CD3PM DATE9.;
FORMAT START_DATE_CM DATE9.;
FORMAT CD2CM DATE9.;
START_DATE_PM = INTNX('MONTH',TODAY(),-1,'B');
CD3PM = INTNX('DAY',START_DATE_PM,2);
START_DATE_CM = INTNX('MONTH',TODAY(),0,'B');
CD2CM = INTNX('DAY',START_DATE_CM,1);
call symputx ('CD3PM', CD3PM);
call symputx ('CD2CM', CD2CM);
RUN;
BTW, coding in mixed case is far easier to read.
DATA DATES;
START_DATE_PM = INTNX('MONTH',TODAY(),-1,'B');
CD3PM = INTNX('DAY',START_DATE_PM,2);
START_DATE_CM = INTNX('MONTH',TODAY(),0,'B');
CD2CM = INTNX('DAY',START_DATE_CM,1);
call symput("CD3PM",put(CD3PM,DATE9.));
call symput("CD2CM",put(CD2CM,DATE9.));
RUN;
%PUT &CD2CM;
%PUT &CD3PM;
Ah, very nice.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.