Help using Base SAS procedures

SET OR APPEND?

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,041
Accepted Solution

SET OR APPEND?

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


Accepted Solutions
Solution
‎04-03-2013 03:12 PM
SAS Employee
Posts: 26

Re: SET OR APPEND?

Posted in reply to jwsquillace

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


All Replies
Respected Advisor
Posts: 3,799

Re: SET OR APPEND?

Posted in reply to robertrao

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

Super User
Posts: 11,343

Re: SET OR APPEND?

Posted in reply to robertrao

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.

Valued Guide
Posts: 634

Re: SET OR APPEND?

Posted in reply to robertrao

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

Occasional Contributor
Posts: 11

Re: SET OR APPEND?

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

Valued Guide
Posts: 634

Re: SET OR APPEND?

Super User
Posts: 5,437

Re: SET OR APPEND?

Posted in reply to robertrao

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
Contributor
Posts: 41

Re: SET OR APPEND?

Posted in reply to robertrao

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.

SAS Employee
Posts: 26

Re: SET OR APPEND?

Posted in reply to robertrao

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

Solution
‎04-03-2013 03:12 PM
SAS Employee
Posts: 26

Re: SET OR APPEND?

Posted in reply to jwsquillace

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

Super Contributor
Posts: 1,041

Re: SET OR APPEND?

Posted in reply to jwsquillace

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;

Super User
Posts: 19,862

Re: SET OR APPEND?

Posted in reply to robertrao

Start a new thread and clarify your questions please.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 591 views
  • 9 likes
  • 9 in conversation