SAS Procedures

Help using Base SAS procedures
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Augusto
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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).

Augusto
Obsidian | Level 7

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).

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

Augusto
Obsidian | Level 7

RW9 I just wanted to update the modate...

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 3288 views
  • 0 likes
  • 2 in conversation