BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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.
BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

7 REPLIES 7
FreelanceReinh
Jade | Level 19

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.

SAS_inquisitive
Lapis Lazuli | Level 10

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. 

http://www2.sas.com/proceedings/sugi23/Begtutor/p50.pdf

Quentin
Super User

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.
BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
SAS_inquisitive
Lapis Lazuli | Level 10

Thanks Quentin.

SAS_inquisitive
Lapis Lazuli | Level 10
Thanks, FreelanceReinhard.
PGStats
Opal | Level 21

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.

PG
SAS_inquisitive
Lapis Lazuli | Level 10

Thanks, PG. This helps a lot.

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!

How to Concatenate Values

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.

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
  • 1322 views
  • 3 likes
  • 4 in conversation