Hi All,
I am trying to pass the macro variables created on local to Remote connection.
The macro variables are dates (start dates and End dates) parameters to extract data from Teradata for the mentioned period. Month(12 months) wise data needs to be extracted from Teradata, i can create 2 date parameters for start and end date and extract the data for entire period of 12 months.
but it is taking a lot lot of time for extraction and once the extraction is complete i need to perform various calculations and generate reports.
Hence i tried to split the start date and end date month wise, and the extraction is faster for months. as the this extraction and calculation will performed in a loop for 12 months.
Since I am not able to pass the Macro variables to Remote (using %SYSLPUT) , i am running the Macro within Rsubmit/ENDRSUBMIT.
/*start of Macro*/
%MACRO SRTDT(BGNDTE=);
%IF %LENGTH(&BGNDTE.) GE 1 %THEN
%DO;
%PUT "START DATE IS NOT MISSING CALCULATING DATES FROM THE GIVEN START DATE";
DATA _NULL_;
INDTE = INPUT("&BGNDTE.",YYMMN6.);
PUT INDTE YYMMN6.;
CALL SYMPUT('INSTDT',(PUT(INTNX('MONTH',INDTE, -12,'B') ,YYMMDD10.)));
CALL SYMPUT('INEDDT',(PUT(INTNX('MONTH',INDTE, 0,'E') ,YYMMDD10.)));
RUN;
%PUT "STARRT DATE ==>> &INSTDT."; /* BGNDTE=202109 "STARRT DATE ==>> 2020-10-01"*/
%PUT "END DATE ==>> &INEDDT."; /*BGNDTE=202109 "END DATE ==>> 2021-09-30"*/
%LET DIFF = %SYSFUNC(INTCK(MONTH,%SYSFUNC(INPUTN(&INSTDT., YYMMDD10.)),%SYSFUNC(INPUTN(&INEDDT., YYMMDD10.))));
%PUT "TOTAL# MONTHS ===>> &DIFF.";
%END;
%ELSE
%DO;
%PUT "START DATE IS MISSING CALCULATING DATES FROM THE SYSTEM DATE.";
DATA _NULL_;
CALL SYMPUT('INSTDT',(PUT(INTNX('MONTH',TODAY(), -13,'B') ,YYMMDD10.)));
CALL SYMPUT('INEDDT',(PUT(INTNX('MONTH',TODAY(), 0,'E') ,YYMMDD10.)));
RUN;
%PUT "STARRT DATE ==>> &INSTDT.";
%PUT "END DATE ==>> &INEDDT.";
%LET DIFF = %SYSFUNC(INTCK(MONTH,%SYSFUNC(INPUTN(&INSTDT., YYMMDD10.)),%SYSFUNC(INPUTN(&INEDDT., YYMMDD10.))));
%PUT "TOTAL# MONTHS ===>> &DIFF.";
%DO i = 1 %TO &DIFF.;
DATA _NULL_;
CALL SYMPUT("SRTDT&i.",(PUT(INTNX('MONTH',%SYSFUNC(INPUTN(&INSTDT., YYMMDD10.)), -&i.,'B') ,YYMMDD10.)));
CALL SYMPUT("ENDDT&i.",(PUT(INTNX('MONTH',%SYSFUNC(INPUTN(&INSTDT., YYMMDD10.)), -&i.,'E') ,YYMMDD10.)));
RUN;
%LET MNTH&i.= %SYSFUNC(INPUTN(&&SRTDT&i., YYMMDD10.),YYMMN6.);
%PUT MONTH ===>>> &&MNTH&i.;
%PUT SRTDT&i. ==>> &&SRTDT&i. ENDDT&i. ==>> &&ENDDT&i.;
%PUT SRTDT&i. ==>> &&SRTDT&i. ENDDT&i. ==>> &&ENDDT&i.;
%let Startdtact&i. = %BQUOTE('&&SRTDT&i.');
%PUT &&Startdtact&i.;
%let Enddtact&i.=%BQUOTE('&&ENDDT&i.');
%let Enddt&i.= %BQUOTE('&&ENDDT&i.');
%put &&Startdtact&i. &&Enddtact&i. &&Enddt&i.;
%END;
%END;
%MEND;
%SRTDT(BGNDTE= );
Kindly let me know if we have any other means to pass the macro variables to Remote connection.
Not sure why you cannot use %SYSLPUT, but here is some cleaner code to generate dates and macro variables.
data _null_;
* create monthly dates for the 12 months prior to the current month;
yr_end_date = intnx('month', date(), -1, 'e');
yr_start_date = intnx('month', yr_end_date, -11);
put yr_start_date= yymmdd10. yr_end_date= yymmdd10.;
do until (yr_start_date > yr_end_date);
i + 1;
mnth_start_date = yr_start_date;
mnth_end_date = intnx('month', mnth_start_date, 0, 'e');
put mnth_start_date= yymmdd10. mnth_end_date= yymmdd10.;
call symput(cats('mnth', i), put(mnth_start_date, yymmn6.));
call symput(cats('mnthstdt', i), quote(put(mnth_start_date, yymmdd10.),"'"));
call symput(cats('mnthenddt', i), quote(put(mnth_end_date, yymmdd10.),"'"));
yr_start_date = intnx('month', yr_start_date, 1);
end;
run;
%macro test_dates;
%do i = 1 %to 12;
%put &i &&mnth&i &&mnthstdt&i &&mnthenddt&i;
%end;
%mend;
%test_dates;
The macro output:
1 202104 '2021-04-01' '2021-04-30'
2 202105 '2021-05-01' '2021-05-31'
3 202106 '2021-06-01' '2021-06-30'
4 202107 '2021-07-01' '2021-07-31'
5 202108 '2021-08-01' '2021-08-31'
6 202109 '2021-09-01' '2021-09-30'
7 202110 '2021-10-01' '2021-10-31'
8 202111 '2021-11-01' '2021-11-30'
9 202112 '2021-12-01' '2021-12-31'
10 202201 '2022-01-01' '2022-01-31'
11 202202 '2022-02-01' '2022-02-28'
12 202203 '2022-03-01' '2022-03-31'
Please, for this problem and from now on, post your code in a code box (click on the "little running man" icon), and indent the code properly to make it readable. This helps everyone, and that helps you.
I don't see anyplace that you are attempting to actually send those macro variables to the remote connection. I do see a macro definition and a call to the macro that will not create any output.
So, how are currently intending to send those values to the remote connection?
Its not a good idea to have RSUBMIT blocks within a macro as the remote SAS session has no idea it is running inside a macro which can cause unexpected processing and logic problems, including passing macro variables between SAS sessions.
Why can't you use %SYSLPUT? If it is because you are creating the macro variables inside a macro, just define them as GLOBAL first using the %GLOBAL statement. Then they will be available to use with %SYSLPUT.
Please post your complete SAS log - its impossible to understand what is happening in your code if you just post bits of it. Run your program using this statement: options mprint; That will enable us to see your source statements.
Also use the </> menu option when posting SAS logs so we can read them more easily.
Not sure why you cannot use %SYSLPUT, but here is some cleaner code to generate dates and macro variables.
data _null_;
* create monthly dates for the 12 months prior to the current month;
yr_end_date = intnx('month', date(), -1, 'e');
yr_start_date = intnx('month', yr_end_date, -11);
put yr_start_date= yymmdd10. yr_end_date= yymmdd10.;
do until (yr_start_date > yr_end_date);
i + 1;
mnth_start_date = yr_start_date;
mnth_end_date = intnx('month', mnth_start_date, 0, 'e');
put mnth_start_date= yymmdd10. mnth_end_date= yymmdd10.;
call symput(cats('mnth', i), put(mnth_start_date, yymmn6.));
call symput(cats('mnthstdt', i), quote(put(mnth_start_date, yymmdd10.),"'"));
call symput(cats('mnthenddt', i), quote(put(mnth_end_date, yymmdd10.),"'"));
yr_start_date = intnx('month', yr_start_date, 1);
end;
run;
%macro test_dates;
%do i = 1 %to 12;
%put &i &&mnth&i &&mnthstdt&i &&mnthenddt&i;
%end;
%mend;
%test_dates;
The macro output:
1 202104 '2021-04-01' '2021-04-30'
2 202105 '2021-05-01' '2021-05-31'
3 202106 '2021-06-01' '2021-06-30'
4 202107 '2021-07-01' '2021-07-31'
5 202108 '2021-08-01' '2021-08-31'
6 202109 '2021-09-01' '2021-09-30'
7 202110 '2021-10-01' '2021-10-31'
8 202111 '2021-11-01' '2021-11-30'
9 202112 '2021-12-01' '2021-12-31'
10 202201 '2022-01-01' '2022-01-31'
11 202202 '2022-02-01' '2022-02-28'
12 202203 '2022-03-01' '2022-03-31'
That still doesn't have anything to RSUBMIT.
Are you perhaps thinking about using PROC SQL to submit SQL code to run in TERADATA?
If you want to use macro variables to generate TERADATA code that refer to date literals then make sure to include the single quotes in the values of the macro variables.
%let start=%bquote('%sysfunc(today(),yymmdd10.)');
proc sql;
connect to teradata ... ;
create table local as select * from connection to teradata
(select * from mytable where mydate = &start)
;
quit;
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.