I have a question about compilation step of SAS data step. When I execute the following code:
SAS issues an error message: ERROR: The variable b in the DROP, KEEP, or RENAME list has never been referenced.
My understanding is that this error message was issued by SAS during compilation of SAS data set option KEEP,
because variable b was not found in description portion of data test. However, data set test1 is created (with 0 variables & 0 rows).
I thought that if there is an error found during compilation then SAS never gets to the execution step where outputs are created.
I would appreciate if you let me know what I am missing.
The data set and all variables are created during compilation time but observations are added to a data set during execution time.
It seems that a wrong variable in the keep option of a set statement doesn't prevent SAS from creating the data set. The error only prevents the execution step from running so that you end up with a data set with zero observations.
I agree with you that one would expect the data set not being created. So good to know that SAS reacts differently.
From SAS engines' point of view, the syntax is not wrong. So first it creates a dataset called TEST1. The next step is to set a dataset called TEST. SAS engine checks for the existence of the dataset TEST. Since TEST exist it goes to the KEEP statement. That is where it firsts encounters an error. That's the reason why it gives an error for wrong referencing in KEEP. But by then the dataset is created, but the variables are not yet defined.
Imagine a door way of 8' by 5' and trying to bring 8' by 6' furniture inside. Even though the whole idea is wrong, it(the ERROR) is identified only when we are at the door way or entry point. By then the room(DATASET) where it goes is defined.
Hope you get an idea of why this happens. This could be explained in a better manner. Just that assigning words for our thought seems surprisingly complicated.
Thanks for your insights. I think I understand it better. This is my
thought process: If we run the following code:
then once word scanner is done with the first line, data set compiler
is going to check for syntax and then creates a "blank" sas data set (just a door 'x' by 'y'):
with no variables and no row. My understanding of blank sas data set
is that both portions (description and actual data) are empty.
If the compilation of the whole data step was successful then descriptor
will have information about variables, otherwise it will remain blank.
For example, if we execute the following code:
blank sas data set will be created, even though the second statement will be not recognized by
compiler and SAS will issue an error message.