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

When rows are appended to a dataset through proc append, I'm finding any indices formerly on that dataset need to be reapplied. Is this result correct/working by design?

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

@mkeintz - From the link you provided:

Appending Data to an Indexed Data File

SAS provides performance improvements when appending a data file to an indexed data file. SAS suspends index updates until all observations are added, and then updates the index with data from the newly added observations. See the APPEND statement in the DATASETS procedure in Base SAS Procedures Guide.

 

This makes it clear indexes are updated once all rows are added (rather than doing it for each row added) which no doubt greatly improves performance.

View solution in original post

7 REPLIES 7
SASKiwi
PROC Star

Whenever you append rows to a SAS dataset, indexes also need to be updated. It is by design.

mkeintz
PROC Star

Interesting.

 

According to the paragraph Updating an Indexed Data File in  Understanding SAS Indexes,

 

Each time that values in an indexed data file are added, modified, or deleted, SAS automatically updates the index. The following activities affect an index as indicated:

which doesn't mention PROC APPEND.  So I suspect the index is not automatically updated when using proc append, but only when the MODIFY statement is used in a DATA step to add/change/delete observations.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SASKiwi
PROC Star

@mkeintz - From the link you provided:

Appending Data to an Indexed Data File

SAS provides performance improvements when appending a data file to an indexed data file. SAS suspends index updates until all observations are added, and then updates the index with data from the newly added observations. See the APPEND statement in the DATASETS procedure in Base SAS Procedures Guide.

 

This makes it clear indexes are updated once all rows are added (rather than doing it for each row added) which no doubt greatly improves performance.

Patrick
Opal | Level 21

@shl007 wrote:

When rows are appended to a dataset through proc append, I'm finding any indices formerly on that dataset need to be reapplied. Is this result correct/working by design?


@shl007 According to the docu @SASKiwi refers to the indexes should get updated when using Proc Append. What makes you believe that this is not the case?

shl007
Obsidian | Level 7

I had done some testing where I had thought the indices weren't sticking, but now I see the indices ARE sticking. Thanks for the clarification!

Tom
Super User Tom
Super User

Are you using SAS datasets?  Or are you appending data into some external database like Oracle?

 

It should work fine for SAS datasets. Try this example:

data class(index=(age));
  set sashelp.class;
  where sex='M';
run;
proc append data=sashelp.class(where=(sex='F')) base=class;
run;

proc print data=class;
  by age;
run;
shl007
Obsidian | Level 7
I'm doing it using SAS datasets. Thanks for the confirmation!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 584 views
  • 0 likes
  • 5 in conversation