I am reading some code that involves a sortedby
option which confuses me a little bit.
So in the first part of the code, the following code was used to readin the data:
data _quotes / view=_quotes;
set taq.&yyyymmdd:;
by symbol date time NOTSORTED ex; length EXN 3.;
run;
Note that there is a NOTSORTED
option here. when I remove it, SAS would return an error ERROR: BY variables are not properly sorted on data set
.
Based on my understanding of how SAS NOTSORTED works, the taq dataset is not properly sorted, but in proper groups.
However, in the following code almost immediately after the previous code (no sort code is involved in between), there in no more NOTSORTED option, but there is no error:
data &outset (sortedby= SYMBOL DATE TIME index=(SYMBOL)
label="WRDS-TAQ NBBO Data");
set _quotes;
by symbol date time;
run;
Therefore, I was wondering if it is because of the sortedby statement that made the difference? I read the SAS documentation, it seems that sortedby will NOT sort the dataset but only specify how the data is currently sorted.
But why did the by statement without the NOTSORTED option work in the second code but not the first code?