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.
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;
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).
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).
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?
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;
RW9 I just wanted to update the modate...
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 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.