Hi,
I have a couple of questions in the following link...
http://support.sas.com/kb/48810
proc contents data=abc._all_ out=abccont(keep=memname) noprint; /*what does the memname refer to*/
run;
ALSO
%macro combdsets;
%do i=1 %to &count;
proc append base=new data=abc.&&name&i force; /*after running this macro step "NEW" dataset is created which has all the datasets???*/
run;
%end;
%mend combdsets;
Thanks
Hi,
try the code below.
libname abc "c:\temp"; /* change the directory if necessary. there should not be any other datasets in this dir. */
data abc.data1 abc.data2 abc.data3;
set sashelp.class;
run;
proc contents data=abc._all_ out=abccont(keep=memname) noprint;run; /* memname is dataset name */
proc sort data=abccont nodupkey;
by memname;
run;
data _null_;
set abccont end=last;
call symputx(cats('name',_n_),memname);
if last then call symputx('count',_n_);
run;
%put _user_; /* allow you to see the macro variables in log file */
%macro combdsets;
%do i=1 %to &count;
proc append base=new data=abc.&&name&i force; /*after running this macro step "NEW" dataset is created which has three datasets(data1,data2,data3) */
run;
%end;
%mend combdsets;
%combdsets
Hi,
try the code below.
libname abc "c:\temp"; /* change the directory if necessary. there should not be any other datasets in this dir. */
data abc.data1 abc.data2 abc.data3;
set sashelp.class;
run;
proc contents data=abc._all_ out=abccont(keep=memname) noprint;run; /* memname is dataset name */
proc sort data=abccont nodupkey;
by memname;
run;
data _null_;
set abccont end=last;
call symputx(cats('name',_n_),memname);
if last then call symputx('count',_n_);
run;
%put _user_; /* allow you to see the macro variables in log file */
%macro combdsets;
%do i=1 %to &count;
proc append base=new data=abc.&&name&i force; /*after running this macro step "NEW" dataset is created which has three datasets(data1,data2,data3) */
run;
%end;
%mend combdsets;
%combdsets
Hi Linlin..
In the below abcount is the dataset name...i still have questions about memname...
Could you explain a little bit
proc contents data=abc._all_ out=abccont(keep=memname) noprint;run; /* memname is dataset name */
proc sort data=abccont nodupkey;
by memname;
run;
Also if I am sure that there are no duplicates of datasets can I ignore the PROC CONTENTS and the PROC SORT?
Run it without the keep= and then with the keep = to see what happens.
Hi,
Yes I did run..
So MEMNAME is a variable produced with the CONTENTS PRocedure which contains the names of the datasets??????
Regards
you have to use proc sort.
below is the output without proc sort:
libname abc "c:\temp"; /* change the directory if necessary. there should not be any other datasets in this dir. */
data abc.data1 abc.data2 abc.data3;
set sashelp.class;
run;
proc contents data=abc._all_ out=abccont(keep=memname name) noprint;run; /* memname is dataset name */
proc print data=abccont;run;
Obs MEMNAME NAME
1 DATA1 Age
2 DATA1 Height
3 DATA1 Name
4 DATA1 Sex
5 DATA1 Weight
6 DATA2 Age
7 DATA2 Height
8 DATA2 Name
9 DATA2 Sex
10 DATA2 Weight
11 DATA3 Age
12 DATA3 Height
13 DATA3 Name
14 DATA3 Sex
15 DATA3 Weight
That's what I get for not running the code
This isn't the type of macro you need to append monthly datasets though. what you need then is something like the following:
%macro append_monthly(new_data=);
proc append base=old_data data=&new_data;
run;
%mend;
Then you call it each month with the new file.
Hi,,
Until I append all the datasets present currently in the library to one single dataset I need to go with
%macro combdsets;
%do i=1 %to &count;
proc append base=new data=abc.&&name&i force;
run;
%end;
%mend combdsets;
After I do that every month fresh data is appended by :
%macro append_monthly(new_data=);
proc append base=old_data data=&new_data;
run;
%mend;
IS IT RIGHT?????
Hi,
Is my understanding of this topic correct?
Regards
I think so.
make sure your "old_data" dataset is the same as your "new" dataset (the cumulative one you created by running your macro);
%macro combdsets;
%do i=1 %to &count;
proc append base=new data=abc.&&name&i force;
run;
%end;
%mend combdsets;
After I do that every month fresh data is appended by :
%macro append_monthly(new_data=);
proc append base=old_data data=&new_data;
run;
%mend;
Read the doc or try it.
Base SAS(R) 9.2 Procedures Guide
The APPEND procedure adds the observations from one SAS data set to the end of another SAS data set.
abccont is the dataset name just created. memname is a variable of dataset abccont, the values of memname are all the dataset names in the library.
One last question:
Is it compulsary that I run the contents and the SOrt????
What is the PROC CONTENTS role here in the code?????
All the datasets I have now are got after running the same Macro
Regards
Proc contents creates the list of datasets to append from the library.
Test what you need in your circumstances by deleting all intermediary files created and then running sections and see what happens.
IMO the proc sort isn't needed, because SAS won't allow duplicate names in a library, but the remaining steps are.
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.