## What is the effect of having notsorted option when data set is actually sorted?

Solved
Super Contributor
Posts: 338

# What is the effect of having notsorted option when data set is actually sorted?

Hi SAS Forum,

I am going to apply this DoW loop to a data set (just a small part of sample data set is shown).

data last_start_npna;

do until(last.account_number);

set set_2;

by bank_number account_number arrears_band notsorted;

if first.Arrears_band and Arrears_band='NPNA'

then Last_NPNA_Start_Month = Current_Date;

end;

format Last_NPNA_Start_Month date9.;

keep bank_number account_number Last_NPNA_Start_month;

run;

Current_date Bank_number Account_number Balance product Arrears_Band (these are variable headings)

 28FEB2010 10 1111111111 45 Personal Loan NPNA 31MAR2010 10 1111111111 45 Personal Loan NPNA 30APR2010 10 1111111111 45 Personal Loan NPNA 31MAY2010 10 1111111111 45 Personal Loan NPNA 31MAR2010 10 2222222222 25 Personal Loan Current 30APR2010 10 2222222222 25 Personal Loan Current

Question:

I have actually sorted the dataset exactly by the set of “by variables’ shown in the code above (yellow).

Proc sort data= set_2;

by bank_number account_number arrears_band;

run;

Would then having the notsorted option harm my final results.

In fact, I Have run with and without notsorted option and both scenarios produce same results but I doubt if SAS has given me correct results for wrong reasons.

Could anyone shed some light?

Thanks

Mirisage

Accepted Solutions
Solution
‎10-21-2012 06:01 PM
Super User
Posts: 23,663

## Re: What is the effect of having notsorted option when data set is actually sorted?

Notsorted is used when your data is GROUPED but not necessarily in a sorted order, as below. If your said BY using that structure without the notsorted option SAS would say it wasn't in order. If it is sorted then you don't need the notsorted option.

G

G

G

B

B

B

D

D

D

All Replies
Solution
‎10-21-2012 06:01 PM
Super User
Posts: 23,663

## Re: What is the effect of having notsorted option when data set is actually sorted?

Notsorted is used when your data is GROUPED but not necessarily in a sorted order, as below. If your said BY using that structure without the notsorted option SAS would say it wasn't in order. If it is sorted then you don't need the notsorted option.

G

G

G

B

B

B

D

D

D

PROC Star
Posts: 8,163

## Re: What is the effect of having notsorted option when data set is actually sorted?

Shouldn't have any adverse effect on the results, but may affect performance.  According to the documentation:

notsorted: specifies that observations with the same BY value are grouped together but are not necessarily sorted in alphabetical or numeric order.

🔒 This topic is solved and locked.