BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Haikuo
Onyx | Level 15

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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.

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

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.

Haikuo
Onyx | Level 15

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

Tom
Super User Tom
Super User

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;

Haikuo
Onyx | Level 15

Thanks, Tom. Your examples are very helpful! I especially like the third one: if 0 then output. really wicked me out.

Haikuo

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 9010 views
  • 5 likes
  • 3 in conversation