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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.