<?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: calculated keyword in proc fedsql in SAS Viya</title>
    <link>https://communities.sas.com/t5/SAS-Viya/calculated-keyword-in-proc-fedsql/m-p/957785#M2743</link>
    <description>&lt;P&gt;Couple of things.&amp;nbsp; First, in your PROC SQL example, you do NOT need the CALCULATED keyword in this case.&amp;nbsp; Just saying "HAVING sum_height&amp;gt;50" works fine.&amp;nbsp; CALCULATED is used in situations where you want to reference a variable you created in the SELECT clause somewhere &lt;EM&gt;else&lt;/EM&gt; in the same SELECT clause.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, in the PROC SQL step and in general in SQL, having variables in your SELECT that do not also appear in your GROUP BY &lt;EM&gt;&lt;STRONG&gt;and&lt;/STRONG&gt;&lt;/EM&gt; that are not being summarized (with a function like SUM, MEAN, MAX, etc.), is not usually what you want (sometimes, but not usually).&amp;nbsp; For ex., here, you have name, weight, and height listed in your SELECT, but only name appears in the group by.&amp;nbsp; I would just recommend that you think carefully about what you're trying to get with this result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the FEDSQL part, the way you have it (with regard to the HAVING clause) is correct - in general, "real" SQL does not allow you to reference a variable you derived in the SELECT clause in the HAVING clause.&amp;nbsp; This is kind of a convenience feature built into PROC SQL, which is a much more forgiving form of SQL.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 31 Jan 2025 11:22:16 GMT</pubDate>
    <dc:creator>quickbluefish</dc:creator>
    <dc:date>2025-01-31T11:22:16Z</dc:date>
    <item>
      <title>calculated keyword in proc fedsql</title>
      <link>https://communities.sas.com/t5/SAS-Viya/calculated-keyword-in-proc-fedsql/m-p/957775#M2742</link>
      <description>&lt;P&gt;Good morning everyone.&lt;/P&gt;&lt;P&gt;I'm trying to use sas Viya with the sas demo. In the documentation I haven't found many examples or explanations for some key topics, such as the conversion of many proc sql codes into proc fedsql. For example, I haven't been able to convert the CALCULATED clause in any way. I'm reporting the example of proc sql and the related conversion attempt with proc fedql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;cas mysess;
caslib mycas path="/shared/viya/homes/sasdemo/c_cas";
libname mycas cas;

caslib _all_ assign;

data mycas.class;
set sashelp.class;
run;

/*PROC SQL*/
proc sql;
create table test_sql as
select name,
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;weight,
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;height,
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum(height) as sum_height
&amp;nbsp; &amp;nbsp;from sashelp.class
group by name
having calculated sum_height &amp;gt; 50;
quit;

&amp;nbsp;
/*FEDSQL VIYA*/
proc fedsql sessref=mysess;
create table mycas.test_fed as
select name,
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;weight,
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;height,
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum(height) as sum_height
&amp;nbsp; &amp;nbsp;from mycas.class
group by name
having  sum(height) &amp;gt; 50;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2025 09:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/calculated-keyword-in-proc-fedsql/m-p/957775#M2742</guid>
      <dc:creator>m_pellegrini</dc:creator>
      <dc:date>2025-01-31T09:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: calculated keyword in proc fedsql</title>
      <link>https://communities.sas.com/t5/SAS-Viya/calculated-keyword-in-proc-fedsql/m-p/957785#M2743</link>
      <description>&lt;P&gt;Couple of things.&amp;nbsp; First, in your PROC SQL example, you do NOT need the CALCULATED keyword in this case.&amp;nbsp; Just saying "HAVING sum_height&amp;gt;50" works fine.&amp;nbsp; CALCULATED is used in situations where you want to reference a variable you created in the SELECT clause somewhere &lt;EM&gt;else&lt;/EM&gt; in the same SELECT clause.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, in the PROC SQL step and in general in SQL, having variables in your SELECT that do not also appear in your GROUP BY &lt;EM&gt;&lt;STRONG&gt;and&lt;/STRONG&gt;&lt;/EM&gt; that are not being summarized (with a function like SUM, MEAN, MAX, etc.), is not usually what you want (sometimes, but not usually).&amp;nbsp; For ex., here, you have name, weight, and height listed in your SELECT, but only name appears in the group by.&amp;nbsp; I would just recommend that you think carefully about what you're trying to get with this result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the FEDSQL part, the way you have it (with regard to the HAVING clause) is correct - in general, "real" SQL does not allow you to reference a variable you derived in the SELECT clause in the HAVING clause.&amp;nbsp; This is kind of a convenience feature built into PROC SQL, which is a much more forgiving form of SQL.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2025 11:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/calculated-keyword-in-proc-fedsql/m-p/957785#M2743</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-31T11:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: calculated keyword in proc fedsql</title>
      <link>https://communities.sas.com/t5/SAS-Viya/calculated-keyword-in-proc-fedsql/m-p/957786#M2744</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&amp;nbsp;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&amp;nbsp;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I read somewhere that the CALCULATED clause is not supported on PROC FEDSQL, and I simply wanted to verify this fact at the syntax level, finding a valid alternative. In the code that I indicated to me it goes into error in sas Viya, I report the error obtained in the log:&lt;/P&gt;&lt;P&gt;80&amp;nbsp;&amp;nbsp; /*FEDSQL*/&lt;BR /&gt;81&amp;nbsp;&amp;nbsp; proc fedsql sessref=mysess;&lt;BR /&gt;82&amp;nbsp;&amp;nbsp; create table test_fed as&lt;BR /&gt;83&amp;nbsp;&amp;nbsp; select name,&lt;BR /&gt;84&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; weight,&lt;BR /&gt;85&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; height,&lt;BR /&gt;86&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum(height) as sum_height&lt;BR /&gt;87&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from mycas.class&lt;BR /&gt;88&amp;nbsp;&amp;nbsp; group by name&lt;BR /&gt;89&amp;nbsp;&amp;nbsp; having calculated sum_height &amp;gt; 50;&lt;BR /&gt;ERROR: Syntax error at or near "SUM_HEIGHT"&lt;BR /&gt;ERROR: The action stopped due to errors.&lt;BR /&gt;ERROR: The FedSQL action was not successful.&lt;BR /&gt;NOTE: PROC FEDSQL has set option NOEXEC and will continue to prepare statements.&lt;BR /&gt;90&amp;nbsp;&amp;nbsp; quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE FEDSQL used (Total process time):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&amp;nbsp;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2025 11:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/calculated-keyword-in-proc-fedsql/m-p/957786#M2744</guid>
      <dc:creator>m_pellegrini</dc:creator>
      <dc:date>2025-01-31T11:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: calculated keyword in proc fedsql</title>
      <link>https://communities.sas.com/t5/SAS-Viya/calculated-keyword-in-proc-fedsql/m-p/957794#M2746</link>
      <description>Right - and the way you currently have your code (in your original post) for FEDSQL is correct:  &lt;BR /&gt;...HAVING sum(height)&amp;gt;50&lt;BR /&gt;...this would also be the case in other versions of true SQL (e.g., T-SQL, PL-SQL)</description>
      <pubDate>Fri, 31 Jan 2025 13:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/calculated-keyword-in-proc-fedsql/m-p/957794#M2746</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-31T13:39:28Z</dc:date>
    </item>
  </channel>
</rss>

