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

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

1 ACCEPTED SOLUTION

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

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.

View solution in original post

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

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.

soham_sas
Quartz | Level 8

@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;

Shmuel
Garnet | Level 18

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;

 

ballardw
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 3952 views
  • 0 likes
  • 6 in conversation