BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DartRodrigo
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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 ;

View solution in original post

5 REPLIES 5
DartRodrigo
Lapis Lazuli | Level 10

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.

Reeza
Super User

I think querying the Dictionary Tables is an easier method.

Take a look at the methods in this thread and see if you can expand them to your problem.

ballardw
Super User

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 ;

DartRodrigo
Lapis Lazuli | Level 10

The code i used works but only prints the last table printed in the log.

DartRodrigo
Lapis Lazuli | Level 10

Thanks Ballard it works

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 830 views
  • 2 likes
  • 3 in conversation