BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
average_joe
Obsidian | Level 7
You don't provide enough info to help you troubleshoot the problem.
average_joe
Obsidian | Level 7

Perhaps this will help. Here is some pseudocode that repeatedly calls a macro that extracts one month of data from a Teradata database and appends the monthly data to a master table of a full year of data. The entire block of code is within a RSUBMIT/ENDRSUBMIT block so it executes on your remote server.

 

rsubmit ...;

%macro get_data (start, end);
    * get one month of data;
    proc sql;
    connect to teradata (...);
    create table month as 
    select * from connection to teradata (
        select *
        from some.table
        where dt between &start and &end
    );
    quit;

    * append single month of data to master table of annual data;
    proc append base=full_year data=month;
    run;
%mend;

data _null_;
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);
    mnth_start_date = yr_start_date;
    mnth_end_date = intnx('month', mnth_start_date, 0, 'e');
    macro_call = cats('%get_data(', quote(put(mnth_start_date, yymmdd10.), "'"), ',', 
            quote(put(mnth_end_date, yymmdd10.), "'"), ');');
    put macro_call=;  * check validity of macro call;
    *call execute (macro_call);  * execute macro call;
    yr_start_date = intnx('month', yr_start_date, 1);
end;
run;

* summarize the full year of data;
proc summary data=full_year ...;
class ...;
var ...;
output ...;
run;

endrsubmit;

Here are the macro calls generated in the data _null_ step.

 

macro_call=%get_data('2021-04-01','2021-04-30');
macro_call=%get_data('2021-05-01','2021-05-31');
macro_call=%get_data('2021-06-01','2021-06-30');
macro_call=%get_data('2021-07-01','2021-07-31');
macro_call=%get_data('2021-08-01','2021-08-31');
macro_call=%get_data('2021-09-01','2021-09-30');
macro_call=%get_data('2021-10-01','2021-10-31');
macro_call=%get_data('2021-11-01','2021-11-30');
macro_call=%get_data('2021-12-01','2021-12-31');
macro_call=%get_data('2022-01-01','2022-01-31');
macro_call=%get_data('2022-02-01','2022-02-28');
macro_call=%get_data('2022-03-01','2022-03-31');

 

Santt0sh
Lapis Lazuli | Level 10
Hi Joe,

Thank you for your quick response!
I would try using the code shared, I also need to check for the user's date input to generate or extract data for nay month.

Thank you!
Santt0sh
Lapis Lazuli | Level 10
Hi!!
Thank you for your suggestions.
I will try the suggested code.

Will keep you posted on this

Regards
Tom
Super User Tom
Super User

I don't understand what you are trying to do.  There is no RSUBMIT block in that code.

 

What is the SAS code you want the macro to generate?  Please show a simplified valid set of SAS code you want to create and explain which parts of it need to by generated by the macro processor.

 

Explain how RSUBMIT blocks come into play.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 19 replies
  • 2078 views
  • 2 likes
  • 6 in conversation