Help using Base SAS procedures

Difference between a procedure's options and statements

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Difference between a procedure's options and statements

Hello

 

I'm trying to understand why certain things are considered options- and are defined when a procedure is invoked- and why others are defined in separate statements;

 

For example:

 

proc means data=input_data n mean sum;

     var analysis_variable;

     class category_variable;

run;

 

Why are the specific descriptive statistics in the "proc means" statement, whereas the analysis variable and classification variable are each their own statement?

 

I remember how to write code better when I understand why things are written in a certain way, so I'm hoping some one can help me understand this difference!

 

Thank you in advance.


Accepted Solutions
Solution
3 weeks ago
Community Manager
Posts: 2,845

Re: Difference between a procedure's options and statements

@Erkika - welcome to the rabbit hole of a 40+ year old programming language!

 

I'll let others answer with their own experience and mnemonics that help them, but I'll say this.  Many procedures have statements that are common and behave in the same expected way.  These statements include VAR, BY, CLASS, FREQ, WEIGHT, and a few others.

 

The PROC statement itself (like "PROC MEANS ....") is one place where the SAS developer can hang some of the options that are specific to this procedure.  Another place they can do that is via a proc-specific statement (a statement name, with arguments and potentially its own options, terminated by a semicolon).

 

If I'm being honest, not all SAS procs are consistent with what becomes an option vs a statement.  More recent procedures are consistent amongst themselves, but lots of older procs (like MEANS) are what they've always been, and cannot be changed because bazillions of production SAS jobs rely on them as they are.

View solution in original post


All Replies
Solution
3 weeks ago
Community Manager
Posts: 2,845

Re: Difference between a procedure's options and statements

@Erkika - welcome to the rabbit hole of a 40+ year old programming language!

 

I'll let others answer with their own experience and mnemonics that help them, but I'll say this.  Many procedures have statements that are common and behave in the same expected way.  These statements include VAR, BY, CLASS, FREQ, WEIGHT, and a few others.

 

The PROC statement itself (like "PROC MEANS ....") is one place where the SAS developer can hang some of the options that are specific to this procedure.  Another place they can do that is via a proc-specific statement (a statement name, with arguments and potentially its own options, terminated by a semicolon).

 

If I'm being honest, not all SAS procs are consistent with what becomes an option vs a statement.  More recent procedures are consistent amongst themselves, but lots of older procs (like MEANS) are what they've always been, and cannot be changed because bazillions of production SAS jobs rely on them as they are.

SAS Employee
Posts: 155

Re: Difference between a procedure's options and statements

Chris is right.  The one thing I will add is we can't say proc whatever and then have a mix of options and variable names in the same statement.  Which is which?  So var ists were put on separate statements.  When a variable list ends and options begin (e.g. after the independent variables in a MODEL statement), a slash is used to indicate the separation.  Now things were pretty much that simple in the 70s and 80s.  Syntax has gotten much more complex since then, but that is the reason why variable lists were not put on the proc statement.

Regular Contributor
Posts: 226

Re: Difference between a procedure's options and statements

\begin{Op.Ed}

After 30 years of programming I am returning to what I learned in university:

it's either data structure (compiled) or algorithm (executed).

 

I like @ChrisHemedinger's notes that many statements are available as subroutines to a wide variety of procedures.

 

I am writing a paper for SESUG.2017 where I highlight the differences between local and global variables

and making the point that we don't think of the several global statements

-- filename, libname, options, running text (titles, footnotes) --

as making entries in the global symbol table.

 

I make a point in my Style Guide to differentiate between the compiler directives

--- attribute, (length, format, label), array, drop/keep, retain, etc. ---

and the executed statements

-- assignment , do, if, link.

 

Once I began to read and write my programs in two passes: data structure, then algorithm,

my debugging and testing time went down my an order of magnitude.

 

\end{Op.Ed}

 

Ron Fehd which? ever! maven

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 195 views
  • 8 likes
  • 4 in conversation