Hi all,
My requirement is to append the summary datasets named data_var1, data_var2, data_var3.....
here var1, var2, var3 are unique set of variables . I need to append all the datasets into a single.
I tried using proc append, following is the code. There are warnings saying that the variables dont exist in base dataset, for this I have used force option. But the output dataset is empty.
%macro Append_summary(in_ds,count,var);
%do i=1 %to &&&count.;
proc append base= summary_stats data=&in_ds._&&&var&i force; run;
%end;
%mend Append_summary;
%Append_summary(summary,var_count,var_name);
var_count and var_name are global macro variables.
Please help me resolve this.
Thanks
If that is indeed your data, and they are the same:
data want; set data_var:; run;
Note the colon, means any dataset with the prefix of data_var.
Secondly why do you have: data_var1, data_var2, data_var3
In the first place. This seems to be a common issue, when doing a procedure over a variable or group, the tendancy is to push out a dataset for each loop. SAS is built on something called by group processing. Get your data into one dataset, with a variable as the group (i.e. what you would split the data out to), then use by in your statement. Doing it this way will make your code smaller, more robust, and produce the one dataset output you want at the end. For instance:
proc means data=have; by mygroup; ...; output out=want; run;
This will produce one dataset, by the mygroup variable - you can apply this logic to anything in SAS, sometimes a change to your data is needed.
Post the complete log of the macro, please.
And inspect your data, there may be nothing in there.
If that is indeed your data, and they are the same:
data want; set data_var:; run;
Note the colon, means any dataset with the prefix of data_var.
Secondly why do you have: data_var1, data_var2, data_var3
In the first place. This seems to be a common issue, when doing a procedure over a variable or group, the tendancy is to push out a dataset for each loop. SAS is built on something called by group processing. Get your data into one dataset, with a variable as the group (i.e. what you would split the data out to), then use by in your statement. Doing it this way will make your code smaller, more robust, and produce the one dataset output you want at the end. For instance:
proc means data=have; by mygroup; ...; output out=want; run;
This will produce one dataset, by the mygroup variable - you can apply this logic to anything in SAS, sometimes a change to your data is needed.
@UshaLatha .. if your id data set and data is like this , please try the below code
data data_var1;
input a b c;
cards;
1 2 3
4 5 6
;
data data_var2;
input d e f;
cards;
7 8 9
10 11 12
;
data data_var3;
input g h i;
cards;
13 14 15
;
data append_var;
set data_var:;
run;
Is summary is a name of library ?
If positive then you missed a dot:
%macro Append_summary(in_ds,count,var);
%do i=1 %to &&&count.;
proc append base= summary_stats data=&in_ds.._&&&var&i force; run;
%end;
%mend Append_summary;
The documentation on Proc Append is pretty clear that you cannot add new variables in the append.
You either have to make your base data set will all of the variables you will ever have before appending any data or use data step code with multiple data sets on the set statement.
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 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.