Dear Data step user
data b;
if 0 then set sashelp.class;
run;
proc print ;run;
since it is never actually executed, why there is still an empty record been created?
Thanks,
Haikuo
A nice explanation of what occurs when can be found in the following paper: http://www.lexjansen.com/nesug/nesug88/sas_supervisor.pdf
The pdv is populated first, thus the five variables exist. One loop was completed, thus one record has to be output. If you want to do something similar, but not have any loop occur, you could run:
data b;
if 0;
set sashelp.class;
run;
That way, you will still get 5 variables, but 0 records.
A nice explanation of what occurs when can be found in the following paper: http://www.lexjansen.com/nesug/nesug88/sas_supervisor.pdf
The pdv is populated first, thus the five variables exist. One loop was completed, thus one record has to be output. If you want to do something similar, but not have any loop occur, you could run:
data b;
if 0;
set sashelp.class;
run;
That way, you will still get 5 variables, but 0 records.
Thanks, Art. That was indeed great paper, I have come across it long before I know anything about pdv, and of course I failed to register. Now everything makes sense, Yeah!
BTW, It has also been known to me that if just wanting the structure, (obs=0) will do, too.
Haikuo
You end up with one record because the data step has looped once and output one record.
See how many records you get with the trivial step. data a; run;
To get 0 records you will need to do something to stop it from outputting the record.
Here are some ways:
data b; set sashelp.class(obs=0); run;
data b; if 0 then set sashelp.class; stop; run;
data b; set sashelp.class; if 0 then output; run;
Thanks, Tom. Your examples are very helpful! I especially like the third one: if 0 then output. really wicked me out.
Haikuo
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.