This chunk of code inherited by previous author.
data test; if 0 then set sashelp.class; stop; run;
This code produces zero observation. Without stop, there is one observation in the test data. I thought non-executable set statment should not produce any observation even without stop statement.
Hi,
During COMPILE time, the DATA step constructs the program data vector (PDV), a logical construct that you can think of as a single row (thus vector) that will hold records as they are processed. When a SET statement executes, it reads a record into the PDV. When an assignemnt statement executes, it changes a value in the PDV. When an OUTPUT statement executes, it outputs the values in the PDV to a dataset.
When the PDV is constructed, it has null values. If you OUTPUT a PDV with null values, you output a record with null values.
Below are a few examples that may be helpful:
140 data OneObs; 141 if 0 then set sashelp.class; 142 *implied OUTPUT; 143 run; NOTE: DATA STEP stopped due to looping. NOTE: The data set WORK.ONEOBS has 1 observations and 5 variables. 144 145 data ZeroObs; 146 if 0 then set sashelp.class; 147 stop; 148 *implied OUTPUT; 149 run; NOTE: The data set WORK.ZEROOBS has 0 observations and 5 variables. 150 151 data OneObs; 152 if 0 then set sashelp.class; 153 output; 154 stop; 155 run; NOTE: The data set WORK.ONEOBS has 1 observations and 5 variables. 156 157 data TwoObs; 158 if 0 then set sashelp.class; 159 output; 160 output; 161 stop; 162 run; NOTE: The data set WORK.TWOOBS has 2 observations and 5 variables.
This is just the standard DATA step behavior. To cite the documentation: "When SAS executes the last statement in the DATA step, all values in the PDV ... are written as a single observation to the data set ..." However, the STOP statement "causes SAS to stop processing the current DATA step immediately", i.e. the PDV is not written to the output dataset.
Please note that the PDV contains only missing values in that one observation you obtain without STOP, not any value from SASHELP.CLASS. The IF condition 0 being false, no values are retrieved from SASHELP.CLASS.
FreelanceReinhard, I checked the difference between compile phase and execution phase before posting this question. I know intializing to missing values was the part of the execution phase. Since the set statment never executes, I thought it does not initialize ; just compile the variable names only. So my take was even without stop statment it should contain only variable names not missing observartions.
Hi,
During COMPILE time, the DATA step constructs the program data vector (PDV), a logical construct that you can think of as a single row (thus vector) that will hold records as they are processed. When a SET statement executes, it reads a record into the PDV. When an assignemnt statement executes, it changes a value in the PDV. When an OUTPUT statement executes, it outputs the values in the PDV to a dataset.
When the PDV is constructed, it has null values. If you OUTPUT a PDV with null values, you output a record with null values.
Below are a few examples that may be helpful:
140 data OneObs; 141 if 0 then set sashelp.class; 142 *implied OUTPUT; 143 run; NOTE: DATA STEP stopped due to looping. NOTE: The data set WORK.ONEOBS has 1 observations and 5 variables. 144 145 data ZeroObs; 146 if 0 then set sashelp.class; 147 stop; 148 *implied OUTPUT; 149 run; NOTE: The data set WORK.ZEROOBS has 0 observations and 5 variables. 150 151 data OneObs; 152 if 0 then set sashelp.class; 153 output; 154 stop; 155 run; NOTE: The data set WORK.ONEOBS has 1 observations and 5 variables. 156 157 data TwoObs; 158 if 0 then set sashelp.class; 159 output; 160 output; 161 stop; 162 run; NOTE: The data set WORK.TWOOBS has 2 observations and 5 variables.
Thanks Quentin.
Try
data test1; run;
/* or */
data test2; stop; run;
/* or */
data test3 test4;
output test3;
stop;
output test4;
run;
and read about What causes a data step to stop executing.
Thanks, PG. This helps a lot.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.