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

Hi ,

I have 20 datasets which share the same variables between them.

Is it better to use Append or Set statements to combine tthem all into a single dataset?

Also that resulting dataset needs to be Updated every month with fresh info

Could you help me figure this

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
jwsquillace
SAS Employee

I search support.sas.com for "proc append samples"

Here are some that may be applicable:

Sample 48810: Append all SAS data sets in a SAS library into 1 SAS data set when the number of SAS data sets varies

http://support.sas.com/kb/48810

Sample 45143: Error trapping with PROC APPEND

http://support.sas.com/kb/45143

Sample 25291: Adding new observations to a SAS data set using PROC APPEND

http://support.sas.com/kb/25291

Sample 33407: Combining Data Sets Containing Character Variables of Different Lengths

http://support.sas.com/kb/33407

One of these may give you ideas to get started.

Cheers,

Jan

View solution in original post

11 REPLIES 11
data_null__
Jade | Level 19

Maybe SET with OPEN=DEFER.  Check the docs for complete info.

ballardw
Super User

Do any of the variables of the same name have different types (numeric or character)?

Do any of the character variables have different assigned lengths?

If yes to either of these questions you need to address them before either option or you will not be happy with the results.

ArtC
Rhodochrosite | Level 12

APPEND may be more efficient in the long run, but it has less flexibility.

kriti
Calcite | Level 5

hi can u help me as to where i can find book "sas macro language 1 essentials"

ArtC
Rhodochrosite | Level 12
LinusH
Tourmaline | Level 20

I'm a bit confused about your statement "resulting dataset needs to be Updated every month with fresh info".

What kind of update is that? Is the repeated append/set operation?

If not, is this concatenation a one time shot? Then there is no need to investigate about efficiency...

Data never sleeps
ghastly_kitten
Fluorite | Level 6

robertrao,

I guess you must have some variables that define the class or a group.

Is it possible in your case that two diffrerent datasets have at least one row with equal class variables and different properties?

Like...

Date               Price

01JAN2010   100   in dataset 1

01JAN2010   200   in dataset 2

If it is and your datasets are not really big consider using merge instead of set or append: then you will have only one value for each class set by the last dataset you merged.

jwsquillace
SAS Employee

In general, PROC APPEND is more efficient because it merely opens the base data set and adds the additional observations to it.

When you use SET to concatenate data sets, as here:

data base;

  set base newdata;

run;

you are rewriting all the base observations in addition to the new data.  When your data sets are small, this is not important.  However, as the base data set gets larger, you wll find the process taking longer and longer.

As Art Carpenter noted, the SET method allows you to apply program logic to the concatenation and is far more flexible than PROC APPEND.

If speed and efficiency are critical, and you simply want to add the observations, use PROC APPEND.

If you require flexibility and program logic, use SET statement.

If you want to summarize statements on key variable(s), use MERGE statement as suggested by @ghastly_kitten

Cheers,

Jan

jwsquillace
SAS Employee

I search support.sas.com for "proc append samples"

Here are some that may be applicable:

Sample 48810: Append all SAS data sets in a SAS library into 1 SAS data set when the number of SAS data sets varies

http://support.sas.com/kb/48810

Sample 45143: Error trapping with PROC APPEND

http://support.sas.com/kb/45143

Sample 25291: Adding new observations to a SAS data set using PROC APPEND

http://support.sas.com/kb/25291

Sample 33407: Combining Data Sets Containing Character Variables of Different Lengths

http://support.sas.com/kb/33407

One of these may give you ideas to get started.

Cheers,

Jan

robertrao
Quartz | Level 8

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;

Reeza
Super User

Start a new thread and clarify your questions please.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 11 replies
  • 2924 views
  • 9 likes
  • 9 in conversation