<?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: Getting over partition error. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875679#M346004</link>
    <description>&lt;P&gt;Let's try to translate those functions into English and then perhaps we can translate them back to standard SQL that PROC SQL can support.&lt;/P&gt;
&lt;P&gt;This part makes no sense&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;coalesce(CA.ATT,' ')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That is saying that if CA.ATT is missing then use a blank instead.&amp;nbsp; But if CA.ATT is missing its value already is blank.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Case when coalesce(CA.ATT,' ') = 'Test' then 1 else 0 end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is saying that when CA.ATT is 'Test' then the result is 1 otherwise it is 0.&amp;nbsp; That is exactly what the comparison&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CA.ATT = 'Test'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;does. Remember that SAS only use BINARY logic unlike the TRI LEVEL logic used by some databases.&amp;nbsp; All comparison are either TRUE (1) or FALSE (0). Even when one or more of the values is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The MAX() aggregate function is the same.&amp;nbsp; It takes the maximum over observations.&amp;nbsp; So the result is TRUE if it is true for ANY of the observations being aggregated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DECODE() seems to be translating 1 to 'Y'.&amp;nbsp; In SAS you would just use a FORMAT to do that.&amp;nbsp; Or you could use a simple CASE statement (which your code already has an example of so it is not clear why it is using DECODE() instead here).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So now we just have&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when max(CA.ATT='Test') then 'Y' else 'N' end&amp;nbsp;as&amp;nbsp;SAM&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You cannot use OVER/PARTITION in PROC SQL.&amp;nbsp; But it is smart enough to remerge aggregate values back onto detail records, so it a lot of cases you don't need it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So are you just trying to do something like?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table ABC as 
select mdm.hpp
     , case when max(CA.ATT='Test') then 'Y' else 'N' end&amp;nbsp;as&amp;nbsp;SAM
from MACM as Mdm
left join CCCT as CA
on MDM.ALKP = CA.ALKP
group by mdm.hpp
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you add some other non grouping and non aggregate variables to the list of selected variables then SAS will remerge the values of SAM back onto the detail records based on the value of MDM.HPP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 14 May 2023 15:53:45 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-05-14T15:53:45Z</dc:date>
    <item>
      <title>Getting over partition error.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875648#M345988</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;Data is coming from two different servers one field is coming from one server and another field is coming from another server. Here ATT&amp;nbsp; feild is coming from one server and&amp;nbsp; Hpp field&amp;nbsp; is coming from another server .Like this&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Proc SQL;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Create table ABC as select * from (&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Select distinct &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Decode (Max(Case when coalesce(CA.ATT,' ') = 'Test' then 1 else 0 end ) over ( partition by MDM.Hpp),1,'Y','N') as SAM from MACM as Mdm&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Left join CCCT as CA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;On MDM.ALKP = CA.ALKP&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Quit;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 10:44:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875648#M345988</guid>
      <dc:creator>Lakshmisukanya</dc:creator>
      <dc:date>2023-05-14T10:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: Getting over partition error.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875655#M345991</link>
      <description>&lt;P&gt;Partition clauses are not supported in the SAS SQL flavor.&lt;/P&gt;
&lt;P&gt;If you want to use such syntax then you need to use explicit SQL that executes directly in a database where such syntax is valid. And of course the story gets even a bit more complicated with a&amp;nbsp;heterogenous join.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need a more detailed answer then you need to provide more detail first (like which type of servers are you connecting to).&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 12:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875655#M345991</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-05-14T12:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Getting over partition error.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875661#M345993</link>
      <description>&lt;P&gt;Hadoop and gcp servers&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 12:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875661#M345993</guid>
      <dc:creator>Lakshmisukanya</dc:creator>
      <dc:date>2023-05-14T12:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Getting over partition error.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875664#M345994</link>
      <description>&lt;P&gt;Since you want to combine tables from different external databases, you cannot use explicit pass-through, and must do the operation in SAS with the available SAS tools. Neither PARTITION nor DECODE is available in SAS&lt;/P&gt;
&lt;P&gt;Please provide usable examples for the datasets as they appear in SAS, and what you expect to get out of these examples.&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 13:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875664#M345994</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-14T13:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Getting over partition error.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875679#M346004</link>
      <description>&lt;P&gt;Let's try to translate those functions into English and then perhaps we can translate them back to standard SQL that PROC SQL can support.&lt;/P&gt;
&lt;P&gt;This part makes no sense&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;coalesce(CA.ATT,' ')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That is saying that if CA.ATT is missing then use a blank instead.&amp;nbsp; But if CA.ATT is missing its value already is blank.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Case when coalesce(CA.ATT,' ') = 'Test' then 1 else 0 end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is saying that when CA.ATT is 'Test' then the result is 1 otherwise it is 0.&amp;nbsp; That is exactly what the comparison&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CA.ATT = 'Test'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;does. Remember that SAS only use BINARY logic unlike the TRI LEVEL logic used by some databases.&amp;nbsp; All comparison are either TRUE (1) or FALSE (0). Even when one or more of the values is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The MAX() aggregate function is the same.&amp;nbsp; It takes the maximum over observations.&amp;nbsp; So the result is TRUE if it is true for ANY of the observations being aggregated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DECODE() seems to be translating 1 to 'Y'.&amp;nbsp; In SAS you would just use a FORMAT to do that.&amp;nbsp; Or you could use a simple CASE statement (which your code already has an example of so it is not clear why it is using DECODE() instead here).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So now we just have&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when max(CA.ATT='Test') then 'Y' else 'N' end&amp;nbsp;as&amp;nbsp;SAM&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You cannot use OVER/PARTITION in PROC SQL.&amp;nbsp; But it is smart enough to remerge aggregate values back onto detail records, so it a lot of cases you don't need it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So are you just trying to do something like?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table ABC as 
select mdm.hpp
     , case when max(CA.ATT='Test') then 'Y' else 'N' end&amp;nbsp;as&amp;nbsp;SAM
from MACM as Mdm
left join CCCT as CA
on MDM.ALKP = CA.ALKP
group by mdm.hpp
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you add some other non grouping and non aggregate variables to the list of selected variables then SAS will remerge the values of SAM back onto the detail records based on the value of MDM.HPP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 15:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-over-partition-error/m-p/875679#M346004</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-14T15:53:45Z</dc:date>
    </item>
  </channel>
</rss>

