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.
@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.
@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.
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.
\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
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: