Help using Base SAS procedures

proc append dynamically

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 80
Accepted Solution

proc append dynamically

Hello, everyone

I have +-100  tables that every month I need to have them updated. I'm using this:

%macro append (table);

     proc append base=&table. data=&table. (obs=0); run;

%mend;

%append(have1);

%append(have2);

%append(have3);

...

...

..

%append(have99);

Is there a better way to do this? Some code that list all tables from the dictionary tables and make the proc append using a Loop?

Thanks for any help.


Accepted Solutions
Solution
‎07-29-2014 09:27 AM
Super User
Super User
Posts: 7,942

Re: proc append dynamically

You could do:

%macro append (table);

     proc append base=&table. data=&table. (obs=0); run;

%mend;

data _null_;

     set sashelp.vtable (where=(libname="XYZ"));

     call execute('%append('||strip(memname)||');');

run;

View solution in original post


All Replies
Super User
Super User
Posts: 7,942

Re: proc append dynamically

Well, I would assign them a library reference of their own, so you can identify those files and then do:

data _null_;

     set sashelp.vtables (where=(libname="your libname");

     by libname;

     if first.libname then call execute('data '||strip(memname)||'; set '||strip(memname));

     else call execute(" "||strip(memname));

     if last.libname then call execute('; run;');

run;

This will generate a datastep with a set statement and then a list of all the datasets in the given libname.  Note if the datasets are not the same then the final one will have more variables (proc append will stop working unless you specify not to).

Frequent Contributor
Posts: 80

Re: proc append dynamically

Hi RW9 thanks, but it's not what I need. If you look at my code I'm updating the same table doing proc append with 'Zero" observations. It seems "strange" but is exactle what I need (once in a while we just have to simple update some tables here).

Super User
Super User
Posts: 7,942

Re: proc append dynamically

Sorry, what do you mean by update tables?  Do you mean new variables to be added or variable type to be changed?  I can't see that your code is actually doing anything, i.e. if I have a dataset with 10 observations and 10 variables and then I append the same 10 variable dataset without any rows, I still have a dataset with 10 rows and 10 variables, nothing has changed?

Solution
‎07-29-2014 09:27 AM
Super User
Super User
Posts: 7,942

Re: proc append dynamically

You could do:

%macro append (table);

     proc append base=&table. data=&table. (obs=0); run;

%mend;

data _null_;

     set sashelp.vtable (where=(libname="XYZ"));

     call execute('%append('||strip(memname)||');');

run;

Frequent Contributor
Posts: 80

Re: proc append dynamically

RW9 I just wanted to update the modate...

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 996 views
  • 0 likes
  • 2 in conversation