Hello, I don't understand why SAS runs fine when I run the following code with drop option before the stat keywords mean and std and gives me the desired result.
proc means data=sashelp.cars (drop=origin) mean std; run;
But when I follow the book's syntax order and put the DROP option after the stat keywords, it crashes
proc means data=sashelp.cars mean std (drop=origin); run;
DROP= is a dataset option, and therefore an integral part of the DATA= procedure option. You must not separate dataset options from their dataset name. Keep in mind that a single statement may have multiple options naming datasets (e.g. DATA=, OUT=, DUPOUT= in a PROC SORT), and it must be clear which dataset options belong to which dataset.
The order in which you specify the options in PROC MEANS matters. When you specify the DROP option before the stat keywords MEAN and STD, the SAS compiler is aware that you want to drop the ORIGIN variable from the calculation of the MEAN and STD. However, when you specify the DROP option after the stat keywords, the SAS compiler does not recognize it, therefore it crashes.
Does that mean the book got the order of the syntax wrong?
it looks like it that way from the documentation on PROC MEANS
No, you also need to look at the documentation covering DATASET OPTIONS
DROP = is a dataset OPTION and must immediately follow the dataset it applies to inside brackets. The PROC MEANS statement has its own options. They don't require brackets and can be specified in any order after PROC MEANS.
Also SAS has not crashed. All that has happened is SAS has stopped running the MEANS step because of the syntax error.
The PROC MEANS statement has its own options. They don't require brackets and can be specified in any order after PROC MEANS.
yeah they do require parentheses, otherwise SAS will give an error, and I just given an example that shows order DOES matter.
You are confusing DATASET OPTIONS - brackets required - and PROCEDURE OPTIONS - no brackets required. See the documentation link in my earlier response.
You are confusing DATASET OPTIONS - brackets required - and PROCEDURE OPTIONS - no brackets required. See the documentation link in my earlier response.
I really have no idea that you're talking about. if you could come up with examples using the sashelp.cars so I can understand what you're trying to convey.
And () are called parenthesis, [] are brackets, do you mean () outside the drop option?
Hopefully this documentation link will help.
A DATASET option example:
proc print data = sashelp.class (drop = age); * Dataset option;
run;
proc print data = sashelp.class label; * procedure statement option;
run;
() are round brackets, [] are square brackets, and {} curly brackets (https://www.englishclub.com/writing/punctuation-brackets.htm).
() are round brackets, [] are square brackets, and {} curly brackets (https://www.englishclub.com/writing/punctuation-brackets.htm).
okay, in other programming communities, like python, they call () strictly parenthesis and [] brackets to avoid confusion when making list and tuples.
There is no DROP option on the PROC MEANS statement. Read the manual.
Your code does not include any DROP option anyway.
The working example is using the DROP= dataset option.
The failed code is an example of misplaced set of dataset options.
DROP= is a dataset option, and therefore an integral part of the DATA= procedure option. You must not separate dataset options from their dataset name. Keep in mind that a single statement may have multiple options naming datasets (e.g. DATA=, OUT=, DUPOUT= in a PROC SORT), and it must be clear which dataset options belong to which dataset.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.