Hi all SAS Users,
Today when I read some discussion about shortening the function calculation with many variables at once.
options mprint;
data quiz_summary;
set pg2.class_quiz;
Name=upcase(Name);
Mean1=mean(Quiz1, Quiz2, Quiz3, Quiz4, Quiz5);
/* Numbered Range: col1-coln where n is a sequential number */
*Mean2=mean(of Quiz--Quiz);
/* Name Prefix: all columns that begin with the specified character string */
Mean3=mean(of Q:);
run;
I have some questions as below:
1. The data statement Mean3=mean(of Q:); will be translated to "dot" or "space" delimiter. Clarifying:
Mean3=mean(of Q:);
/*explain1 : equal to*/
Mean3=mean(Q1 Q2 Q3);
/*explain2: or */
Mean3=mean(Q1, Q2, Q3);
I know the explain1 is wrong but I am not sure maybe SAS has some special treatment for function like that. I used option mprint and putlog but cannot see what is the long version of Mean3=mean(of Q:); . Is there any way to do so btw?
2. We all know that dash can be used to group a list of range of variables in PDV as below
In this case, they group the range from Quiz1 to AvgQuiz by the double dash.
So, I applied to my code and it went wrong
data quiz_summary;
set pg2.class_quiz;
Name=upcase(Name);
Mean1=mean(Quiz1 Quiz2 Quiz3 Quiz4 Quiz5);
Mean2=mean(of Quiz--Quiz);
run;
The log is
49 data quiz_summary;
50 set pg2.class_quiz;
51 Name=upcase(Name);
52 Mean1=mean(Quiz1, Quiz2, Quiz3, Quiz4, Quiz5);
53 /* Numbered Range: col1-coln where n is a sequential number */
54 Mean2=mean(of Quiz--Quiz);
____
71
ERROR: Variable Quiz cannot be found on the list of previously defined variables.
ERROR 71-185: The MEAN function call does not have enough arguments.
The thing here, if the longer version of the statement Mean2=mean(of Quiz--Quiz); is Mean2=mean(Quiz1 Quiz2 .....Quiz5 Mean1), I accept that I am wrong, but they should announce me the error below rather than the above error
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, ',', -, /,
<, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL,
NOTIN, OR, [, ^=, {, |, ||, ~=.
3. Apart from that, so, can you tell me how to fix the code above Mean2=mean(of Quiz--Quiz); with the use of double dash to calculate the function of variables with analogous names.
Warmest regards,
Phil.
... View more