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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

View solution in original post

2 REPLIES 2
Reeza
Super User

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

art297
Opal | Level 21

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 2441 views
  • 4 likes
  • 3 in conversation