Hi guys,
I'm creating a query to append Datasets using a macro, because, sometimes i need to append data only from 3 months ago.
This code below works well until i create a data set inside of the macro to append the tables:
%GLOBAL YEARDT
ANO
MES
INTERVALO
ANOI
MESI
BASES;
%LET YEARDT = %SYSFUNC(DATE(),YYMMP10.);
%LET ANO = %SUBSTR(&YEARDT.,1,4);
%LET MES = %SUBSTR(&YEARDT.,6,2);
%PUT &ANO&MES.;
%MACRO APPEND(NUM);
%DO I = 1 %TO #
%LET INTERVALO = %SYSFUNC(PUTN(%SYSFUNC(INTNX(MONTH,%SYSFUNC(DATE()),-&&I.)),YYMMP10.));
%LET ANOI = %SUBSTR(&INTERVALO.,1,4);
%LET MESI = %SUBSTR(&INTERVALO.,6,2);
%LET BASES = BASE_WO.BASE_WO_&ANOI&MESI.;
%PUT &BASES.;
%END;
%MEND;
%APPEND(2);
In the %APPEND(2); i'd like to append how much months i need(Type a number).
My tables names has dates at the end of their names in this format = 201501;
How can i do that to append tables ?
Thank you before anything,
Rodrigo Dartibali Elias
Show the code you used that didn't work.
A likely cause is either a missing semi colon or the location of the loop:
%macro dummyset( loops=5);
data want;
set
%do I = 1 to &loops;
libref.myset&i /* NOTE: No ; here*/
%end; /* the LOOP but NOT the set statement*/
; /* This ; ends the SET statement*/
run;
%mend;
So your code should make sure you are NOT generating any extra ;
Possibly:
data want;
set
%yourmacroname ()
;
run;
Use OPTIONS MPRINT to see the resolved code and look for an extra ;
One more thing. When i use the macro Bases in %put statement inside do loop, it prints all tables names into the log(Works),
When i put the same macro in the set statement it doesn't work.
Show the code you used that didn't work.
A likely cause is either a missing semi colon or the location of the loop:
%macro dummyset( loops=5);
data want;
set
%do I = 1 to &loops;
libref.myset&i /* NOTE: No ; here*/
%end; /* the LOOP but NOT the set statement*/
; /* This ; ends the SET statement*/
run;
%mend;
So your code should make sure you are NOT generating any extra ;
Possibly:
data want;
set
%yourmacroname ()
;
run;
Use OPTIONS MPRINT to see the resolved code and look for an extra ;
The code i used works but only prints the last table printed in the log.
Thanks Ballard it works
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.