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

Hi Members,

 

I am using SAS studio for learning and I submitted the below program and SAS run without any problem.

 

data test1;
set sashelp.cars;
keep make model type origin;

data test2;
set sashelp.shoes;

proc print data=test2;

So my question is, what is the usefulness or necessity of the run statement when my program is able to run smoothly even with any run statements?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Sounds right to me.  So first you submitted:

proc print data=sashelp.cars;

So SAS is waiting for you to finish speaking before it gives you an answer.

Then you submitted:

proc print data=sashelp.cars;

And now SAS sees the new PROC starting so it runs the first one.  And it is still waiting for you to finish the second proc.

Try now submitting:

  var make model;
run;

And see what you get. Compare it to the output of the first PROC PRINT.

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

It is good programming practice. In some situations, a RUN; is required. Just because it isn't needed in this situation, it is needed in other situations. So get in the habit, you will avoid future problems.

 

But really, let's not debate this, it is good programming practice, so just do it for that reason. It is also good programming practice to place indentation in your code, as explained elsewhere in Maxim 12. Just do it.

--
Paige Miller
Kurt_Bremser
Super User

Consider it good practice.

See this:

data class;
set sashelp.class;
call symputx('count',_n_);

proc print data=class;

Now, insert a %put for debugging:

data class;
set sashelp.class;
call symputx('count',_n_);

%put &count.;

proc print data=class;

 

Tom
Super User Tom
Super User

The RUN statement let's SAS know when the code for the current step is finished (or for interactive procs when the current run group is finished.)  Without that SAS will have to figure out that you were done with the code for the current step.  It knows you are done when it either sees the start of the next step or the end of the file.  Note that SAS/Studio will add code after your code that will include a RUN statement so the last step will run even though your SAS session is still open.

 

There are a lot of ways you can confuse yourself about what your code means (you can't confuse the SAS compiler).  Being sure to explicitly include the RUN statement (or QUIT statement for procedures that need that) will make it so you don't get confused about which statements are part of which step.  Or in the case of macro statements (like %PUT and %LET) and global statements (like TITLE and FOOTNOTE) whether they are run between two steps.

 

ChrisNZ
Tourmaline | Level 20

SAS added a run statement is this "ran without any problem".

The last step (proc print here) would not run if not terminated by a run statement, as SAS has no way of knowing the step is finished and you want it to run.

Dritan007
Fluorite | Level 6

If a RUN or QUIT statement is not used at the end of a step, SAS assumes that the beginning of a new step implies the end of the previous step.

If a RUN or QUIT statement is not used at the end of the last step in a program, SAS Studio and SAS Enterprise Guide automatically submit a RUN and QUIT statement after the submitted code.

The RUN statement is not required between steps in a SAS program. However, it is a best practice to use a RUN statement because it can make the SAS program easier to read and the SAS log easier to understand when debugging.

marcuswong
Fluorite | Level 6

@PaigeMiller  @ChrisNZ  @Tom  @Kurt_Bremser  @Dritan007 

 

Is there a way to disable the auto run statement in SAS studio?

 

I want to convince myself that the last proc print step in the below program will not run:

data test1;
set sashelp.cars;
keep make model type origin;

data test2;
set sashelp.shoes;

proc print data=test2;

 

Tom
Super User Tom
Super User
There is an ICON on the code editor window named GO INTERACTIVE.
marcuswong
Fluorite | Level 6

@Tom  I'm totally confused now.

 

I login SAS studio, click go-interactive ,

 

write this one liner code: proc print data=sashelp.cars;

 

first click of running man no print results.

second click of running man there is print result.

 

Tom
Super User Tom
Super User

Sounds right to me.  So first you submitted:

proc print data=sashelp.cars;

So SAS is waiting for you to finish speaking before it gives you an answer.

Then you submitted:

proc print data=sashelp.cars;

And now SAS sees the new PROC starting so it runs the first one.  And it is still waiting for you to finish the second proc.

Try now submitting:

  var make model;
run;

And see what you get. Compare it to the output of the first PROC PRINT.

marcuswong
Fluorite | Level 6

@PaigeMiller  @ChrisNZ  @Tom  @KurtBremser  @Dritan007 

Thank you for the guidance!

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
  • 10 replies
  • 4229 views
  • 9 likes
  • 6 in conversation