Hi all,
I just finished lesson 5 level 2 practice and getting the correct responses with no syntax errors. However, upon comparing my syntax, it is different than the proposed answer. Can someone please help me understand why you would use the proposed answer over the syntax I provide? (I feel like I am getting a bit confused as the practices sometimes have us try new syntax, meanwhile, I am using syntax that was just practiced earlier in the session and I am not sure how the new syntax is different than the syntax I wrote?)
Practice Steps are:
Create a new program. Write a PROC MEANS step to analyze rows from pg1.np_westweather with the following specifications:
My answer is below:
proc means data=PG1.NP_WESTWEATHER;
where Precip =0;
class name year;
ways 2;
output out=rainstats N=RainDays sum=TotalRain;
run;
Proposed Answer:
proc means data=pg1.np_westweather noprint;
where Precip ne 0;
var Precip;
class Name Year;
output out=rainstats(where=(_type_=3))
n=RainDays sum=TotalRain;
run;
where Precip =0;
is not equal to this:
where Precip ne 0;
Which is your biggest difference.
Because they said:
I suspect that's why they used the data set option of WHERE. WAYS is another way to do this and I can think of at least two more ways to accomplish this within PROC MEANS - NWAY option and TYPES statements.
Your solution
My answer is below: proc means data=PG1.NP_WESTWEATHER; where Precip =0; class name year; ways 2; output out=rainstats N=RainDays sum=TotalRain; run;
has the potential to get a different result because without a VAR statement which variable gets stuck into totalrain may be problematic.
Compare the results from these two snippets:
proc means data=SASHELP.Class; class sex ; ways 1; output out=work.summ1 N=count sum=total; run; proc means data=SASHELP.Class; class sex; ways 1; var weight; output out=work.summ2 N=count sum=total; run;
The variable summarized in the first code is the FIRST numeric not used in class variable(if any class variables are numeric).
The second summarizes a specific variable.
When the data has few variables you may get lucky and get the same answer as needed but if the order of variables is other than expected, or not considered prior to writing the code, then you get interesting results.
Note that a frequently helpful feature of Proc Means / summary is autoname to name output variables:
proc means data=SASHELP.Class; class sex ; ways 1; output out=work.summ3 n= sum= mean= / autoname; run;
Which will create the count, sum and mean of all numeric variables (not used on class, freq or weight statements) and appends the statistic to the variable name.
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!
Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.
Find more tutorials on the SAS Users YouTube channel.