<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Double dash error in calculation? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731075#M227713</link>
    <description>&lt;P&gt;Variable list rules&lt;/P&gt;
&lt;P&gt;The : after part of variable name means "use all variables that start with the common characters".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Q: means try to use every variable whose name starts with Q. Causes invalid data messages with functions that expect all numeric variables, like Mean, Sum if any of the variables are character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The -- means variables that are consecutively numbered in the variable order list (or adjacent columns). Starts with the first variable and goes the the last. Again if any of the variables in the list are of different types expect issues. But the NAME has to be complete.&lt;/P&gt;
&lt;P&gt;Your example with Quiz -- Quiz fails because you have no variable named Quiz at all. SAS quite often stops at the first error of certain types. Doubt that there are going to be changes made in that account. &lt;/P&gt;
&lt;P&gt;You would have to use Quiz1 -- Quiz5 , or if the variables are not actually in column order you can use the single dash Quiz1 - Quiz5 which requires sequentially numbered variable names but does not care about position in the PDV. There cannot be gaps in the sequence though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The inline statistical functions require a comma delimiter separating: a valid variable, a literal value, a valid list structure, or a combination of them. This is syntactically correct as long as the variables exist, are in the correct order for b -- var2 to make sense, and all a variables are numeric:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x = sum( a,b,c, of Var1-Var3, of b -- var2, of a:);&lt;/P&gt;
&lt;P&gt;realizing of course that some variables will be duplicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am afraid that you have describe what you mean by analogous names in "; with the use of &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;double dash&lt;/STRONG&gt;&lt;/FONT&gt; to calculate the function of variables with analogous names."&amp;nbsp; The double dash only has one meaning: sequential columns or PDV data order, nothing else. If the variables are not adjacent you cannot use a single -- to get all of them. You can use different intervals if the sub-groups are adjacent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not so much in function but array definitions I have used things like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array v (*) q1-q18 q21a--q21z q25 q27 q30 q34-q80;&lt;/P&gt;
&lt;P&gt;To define a list of variables that had similar characteristics that I needed to work with. Note the mixing of types, sequentially named, pdv order, individually named.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Apr 2021 22:33:09 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-04-02T22:33:09Z</dc:date>
    <item>
      <title>Double dash error in calculation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731068#M227711</link>
      <description>&lt;P&gt;Hi all SAS Users,&lt;/P&gt;
&lt;P&gt;Today when I read some discussion about shortening the function calculation with many variables at once.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have some questions as below:&lt;/P&gt;
&lt;P&gt;1. The data statement&amp;nbsp;&lt;STRONG&gt;Mean3=mean(of Q:);&lt;/STRONG&gt; will be translated to "&lt;STRONG&gt;dot&lt;/STRONG&gt;" or "&lt;STRONG&gt;space&lt;/STRONG&gt;" delimiter. Clarifying:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Mean3=mean(of Q:);

/*explain1 : equal to*/
Mean3=mean(Q1 Q2 Q3);
/*explain2: or */
Mean3=mean(Q1, Q2, Q3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know the &lt;STRONG&gt;explain1&lt;/STRONG&gt; is wrong but I am not sure maybe SAS has some special treatment for function like that. I used &lt;STRONG&gt;option mprint&lt;/STRONG&gt; and &lt;STRONG&gt;putlog&lt;/STRONG&gt; but cannot see what is the long version of&amp;nbsp;&lt;CODE class=" language-sas"&gt;Mean3=mean(of Q:);&lt;/CODE&gt;&amp;nbsp;. Is there any way to do so btw?&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;2. We all know that dash can be used to group a list of range of variables in PDV&amp;nbsp; as below&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Phil_NZ_0-1617400642497.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56863i4F2A954B89BE7332/image-size/large?v=v2&amp;amp;px=999" role="button" title="Phil_NZ_0-1617400642497.png" alt="Phil_NZ_0-1617400642497.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In this case, they group the range from Quiz1 to AvgQuiz by the double dash.&lt;/P&gt;
&lt;P&gt;So, I applied to my code and it went wrong&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data quiz_summary;
	set pg2.class_quiz;
	Name=upcase(Name);
	Mean1=mean(Quiz1 Quiz2 Quiz3 Quiz4 Quiz5);
	Mean2=mean(of Quiz--Quiz);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The thing here, if the longer version of the statement&amp;nbsp;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&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, ',', -, /, 
              &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, 
              NOTIN, OR, [, ^=, {, |, ||, ~=.  &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Apart from that, so, can you tell me how to fix the code above&amp;nbsp;Mean2=mean(of Quiz--Quiz); with the use of &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;double dash&lt;/STRONG&gt;&lt;/FONT&gt; to calculate the function of variables with analogous names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warmest regards,&lt;/P&gt;
&lt;P&gt;Phil.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 22:05:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731068#M227711</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-04-02T22:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Double dash error in calculation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731074#M227712</link>
      <description>&lt;P&gt;You can reference a list of variables in the mean function using any of the notations in below example and as documented &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lepg&amp;amp;docsetTarget=p08ywlo51p6ezbn1lde9f0aphq6r.htm&amp;amp;locale=en" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Be careful when using the double dash notation. Double dash returns the variables according to their place in the pdv (see example below).&lt;/P&gt;
&lt;P&gt;I assume your syntax (of quiz--quiz) doesn't work because this is not a list but the same variable repeated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  array quiz {*} 8 q1 q2 var q3 q4 q5 (1,2,100,3,4,5);
  output;
  stop;
run;

data test;
  set have;
  array a1 {*} q:;
  x=mean(of q:);
  y=mean(of a1[*]);
  output;
  array a2 {*} q1-q5;
  x=mean(of q1-q5);
  y=mean(of a2[*]);
  output;
  array a3 {*} q1--q5;
  x=mean(of q1--q5);
  y=mean(of a3[*]);
  output;
run;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1617403841848.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56867i5A0FBD6699650231/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1617403841848.png" alt="Patrick_0-1617403841848.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 22:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731074#M227712</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-02T22:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Double dash error in calculation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731075#M227713</link>
      <description>&lt;P&gt;Variable list rules&lt;/P&gt;
&lt;P&gt;The : after part of variable name means "use all variables that start with the common characters".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Q: means try to use every variable whose name starts with Q. Causes invalid data messages with functions that expect all numeric variables, like Mean, Sum if any of the variables are character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The -- means variables that are consecutively numbered in the variable order list (or adjacent columns). Starts with the first variable and goes the the last. Again if any of the variables in the list are of different types expect issues. But the NAME has to be complete.&lt;/P&gt;
&lt;P&gt;Your example with Quiz -- Quiz fails because you have no variable named Quiz at all. SAS quite often stops at the first error of certain types. Doubt that there are going to be changes made in that account. &lt;/P&gt;
&lt;P&gt;You would have to use Quiz1 -- Quiz5 , or if the variables are not actually in column order you can use the single dash Quiz1 - Quiz5 which requires sequentially numbered variable names but does not care about position in the PDV. There cannot be gaps in the sequence though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The inline statistical functions require a comma delimiter separating: a valid variable, a literal value, a valid list structure, or a combination of them. This is syntactically correct as long as the variables exist, are in the correct order for b -- var2 to make sense, and all a variables are numeric:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x = sum( a,b,c, of Var1-Var3, of b -- var2, of a:);&lt;/P&gt;
&lt;P&gt;realizing of course that some variables will be duplicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am afraid that you have describe what you mean by analogous names in "; with the use of &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;double dash&lt;/STRONG&gt;&lt;/FONT&gt; to calculate the function of variables with analogous names."&amp;nbsp; The double dash only has one meaning: sequential columns or PDV data order, nothing else. If the variables are not adjacent you cannot use a single -- to get all of them. You can use different intervals if the sub-groups are adjacent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not so much in function but array definitions I have used things like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array v (*) q1-q18 q21a--q21z q25 q27 q30 q34-q80;&lt;/P&gt;
&lt;P&gt;To define a list of variables that had similar characteristics that I needed to work with. Note the mixing of types, sequentially named, pdv order, individually named.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 22:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731075#M227713</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-02T22:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Double dash error in calculation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731078#M227714</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your explanation, I am aware of what you mentioned. I rarely use a double dash in calculating, mainly for importing data from CSV as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; suggested previously. Now, when using double dash, I need to open debugger to see what inside PDV before confidently hit the calculation. But yeah, it is how I learn SAS by putting myself into many situations to find the answer, even, it is not an optimized way to do things, but I will learn to deal with a problem from many angles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 22:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731078#M227714</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-04-02T22:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Double dash error in calculation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731079#M227715</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've updated my previous post. I assume your syntax didn't work because you're repeating the variable so it's not really a list.&lt;/P&gt;
&lt;P&gt;You can always issue a proc contents with order=varnum to quickly check the order of vars in a table.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 22:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731079#M227715</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-02T22:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: Double dash error in calculation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731080#M227716</link>
      <description>&lt;P&gt;Personally I avoid use of double dashes and variable shortening (Q:) because the results can be unpredictable AND if you are collaborating with other SAS users it is much better to be explicit in your code so they can see exactly what variables are involved. I'm OK with variable lists though.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 23:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731080#M227716</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-04-02T23:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Double dash error in calculation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731092#M227722</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Too many great things for me to enjoy in one discussion. Thank you for making my weekend.&lt;/P&gt;
&lt;P&gt;Many thanks and warmest regards.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 00:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731092#M227722</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-04-03T00:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: Double dash error in calculation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731101#M227731</link>
      <description>&lt;P&gt;You left out the positional lists that select only one type of variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first-numeric-last
first-character-last&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;1174  data test;
1175   set sashelp.class ;
1176   array _c name-character-weight ;
1177   array _n name-numeric-weight ;
1178   put (_c(*)) (=);
1179   put (_n(*)) (=);
1180   stop;
1181  run;

Name=Alfred Sex=M
Age=14 Height=69 Weight=112.5
&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Apr 2021 03:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-dash-error-in-calculation/m-p/731101#M227731</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-03T03:33:59Z</dc:date>
    </item>
  </channel>
</rss>

