BookmarkSubscribeRSS Feed
gearut
Calcite | Level 5
Hi.
I have a question about compilation step of SAS data step. When I execute the following code:

data test;
a=12;
run;

data test1;
set test(keep=b);
run;

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.

Thanks, George
7 REPLIES 7
TMorville
Calcite | Level 5
removed by user Message was edited by: TMorville
Patrick
Opal | Level 21
Hi George

Interesting observation.

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.

HTH
Patrick
Sandhya
Fluorite | Level 6
Hi George,

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.

Regards,
Sandhya.
Patrick
Opal | Level 21
Interestingly variable "d" gets added to "test1" but "c" not (SAS9.2 TS Level 2M3 / Win 7 64bit).

data test;
a=12;
c=12;
run;

data test1;
set test(keep=c b);
d=12;
run;

proc contents data=test1;
quit; Message was edited by: Patrick
Sandhya
Fluorite | Level 6
I just copied the code and executed it.

Still the dataset is empty with no variable.

Sandy.
Patrick
Opal | Level 21
Hi Sandy
Just to show that in my environment variable "d" gets added:


NOTE: This session is executing on the X64_VSPRO platform.

NOTE: SAS initialization used:
real time 0.74 seconds
cpu time 0.60 seconds

1 data test;
2 a=12;
3 c=12;
4 run;

NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


5
6 data test1;
7 set test(keep=c b);
ERROR: The variable b in the DROP, KEEP, or RENAME list has never been referenced.
8 d=12;
9 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEST1 may be incomplete. When this step was stopped there were 0 observations and 1 variables.





Alphabetic List of Variables and Attributes

# Variable Type Len

1 d Num 8
gearut
Calcite | Level 5
Sandy and Patrick:

Thanks for your insights. I think I understand it better. This is my
thought process: If we run the following code:


data test;
.....
run;

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:


data test;
bbbbbbb;
run;

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.


Thanks and Happy New Year !

George

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 976 views
  • 0 likes
  • 4 in conversation