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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 8039 views
  • 5 likes
  • 3 in conversation