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

I have two sorted SAS data sets and now want to interleave them together.  I am noticing after interleaving them using the same by variable that both are sorted on, the sort indicator is not retained in the resulting dataset.  Does anyone know why after interleaving these datasets the sort indicator (I'm validating using proc contents) would no longer be set ?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The DATA step has the potential to destroy the sorted order.  For example, this would be a legal program:

data new;

   set already_sorted;

   by id;

   if amount > 1000 then id='ABC';

run;

The new data set is not sorted, even though the incoming data set is sorted.

If you know that the sorted order is going to be maintained, you can add that as a data set option:

data interleaved (sortedby=id);

   set a b;

   by id;

run;

If you then run a PROC CONTENTS, the sort indicator will be maintained.  However, the second related indicator (VALIDATED) will not be set because SAS has not validated the sorted order.

Finally, when you use the SORTEDBY data set option, you better be correct.  If you are wrong, the data will not be in order but subsequent PROC SORTs will be skipped.  There are ways around that, but it's better not to get into that situation in the first place.

Good luck.

View solution in original post

1 REPLY 1
Astounding
PROC Star

The DATA step has the potential to destroy the sorted order.  For example, this would be a legal program:

data new;

   set already_sorted;

   by id;

   if amount > 1000 then id='ABC';

run;

The new data set is not sorted, even though the incoming data set is sorted.

If you know that the sorted order is going to be maintained, you can add that as a data set option:

data interleaved (sortedby=id);

   set a b;

   by id;

run;

If you then run a PROC CONTENTS, the sort indicator will be maintained.  However, the second related indicator (VALIDATED) will not be set because SAS has not validated the sorted order.

Finally, when you use the SORTEDBY data set option, you better be correct.  If you are wrong, the data will not be in order but subsequent PROC SORTs will be skipped.  There are ways around that, but it's better not to get into that situation in the first place.

Good luck.

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!

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
  • 1 reply
  • 732 views
  • 0 likes
  • 2 in conversation