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
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
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
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.