<?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 Proc SQL Create table where none of a given primary key match a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855567#M338115</link>
    <description>&lt;P&gt;I'm looking to create a table through proc sql that takes a larger list with multiple entries for a primary key, and want to return rows with that have a primary key where none of a given criteria occur.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Imagine this list below as my original list called work.names . If a name has a non-null login_id value for any of its rows, I don't want any row with that name returned at all. I only want names where all rows have a NULL login_id, ideally with only one entry for each name/primary key.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Name&lt;/TD&gt;&lt;TD&gt;Login_ID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Alejandra Bravo&lt;/TD&gt;&lt;TD&gt;1394&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Alejandra Bravo&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vincent Crisanti&lt;/TD&gt;&lt;TD&gt;6687&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vincent Crisanti&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Stephen Holyday&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Stephen Holyday&lt;/TD&gt;&lt;TD&gt;5548&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Stephen Holyday&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Lily Cheng&lt;/TD&gt;&lt;TD&gt;3392&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Amber Morley&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Amber Morley&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Amber Morley&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Frances Nunziata&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Frances Nunziata&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And from this list should return something like:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Name&lt;/TD&gt;&lt;TD&gt;Login_ID_3_1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Amber Morley&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Frances Nunziata&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My initial idea was to use this code:&lt;/P&gt;&lt;P&gt;select distinct *,&lt;BR /&gt;rank () over(partition by name order by LOGIN_ID) as RANK&lt;/P&gt;&lt;P&gt;from&amp;nbsp;work.names&lt;/P&gt;&lt;P&gt;where RANK = 1 and missing(LOGIN_ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, this does not work because rank over partition is not supported in proq sql. So perhaps there's another route to getting the data i need? It doesn't need to be a way to rank data, I just need to get rows with names that have no non-null values. Any ideas?&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jan 2023 14:41:33 GMT</pubDate>
    <dc:creator>aazzarello</dc:creator>
    <dc:date>2023-01-25T14:41:33Z</dc:date>
    <item>
      <title>Proc SQL Create table where none of a given primary key match a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855567#M338115</link>
      <description>&lt;P&gt;I'm looking to create a table through proc sql that takes a larger list with multiple entries for a primary key, and want to return rows with that have a primary key where none of a given criteria occur.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Imagine this list below as my original list called work.names . If a name has a non-null login_id value for any of its rows, I don't want any row with that name returned at all. I only want names where all rows have a NULL login_id, ideally with only one entry for each name/primary key.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Name&lt;/TD&gt;&lt;TD&gt;Login_ID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Alejandra Bravo&lt;/TD&gt;&lt;TD&gt;1394&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Alejandra Bravo&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vincent Crisanti&lt;/TD&gt;&lt;TD&gt;6687&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Vincent Crisanti&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Stephen Holyday&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Stephen Holyday&lt;/TD&gt;&lt;TD&gt;5548&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Stephen Holyday&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Lily Cheng&lt;/TD&gt;&lt;TD&gt;3392&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Amber Morley&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Amber Morley&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Amber Morley&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Frances Nunziata&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Frances Nunziata&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And from this list should return something like:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Name&lt;/TD&gt;&lt;TD&gt;Login_ID_3_1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Amber Morley&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Frances Nunziata&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My initial idea was to use this code:&lt;/P&gt;&lt;P&gt;select distinct *,&lt;BR /&gt;rank () over(partition by name order by LOGIN_ID) as RANK&lt;/P&gt;&lt;P&gt;from&amp;nbsp;work.names&lt;/P&gt;&lt;P&gt;where RANK = 1 and missing(LOGIN_ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, this does not work because rank over partition is not supported in proq sql. So perhaps there's another route to getting the data i need? It doesn't need to be a way to rank data, I just need to get rows with names that have no non-null values. Any ideas?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 14:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855567#M338115</guid>
      <dc:creator>aazzarello</dc:creator>
      <dc:date>2023-01-25T14:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Create table where none of a given primary key match a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855570#M338116</link>
      <description>&lt;P&gt;This should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select distinct *
    from have 
    group by name
    having sum(login_id^='NULL')=0;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From now on, we cannot work with data in screen captures or file attachments. We need data presented as WORKING data step code which you can type in yourself, or follow &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 14:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855570#M338116</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-25T14:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Create table where none of a given primary key match a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855572#M338117</link>
      <description>&lt;P&gt;My mistake. I did not include that the login column is a varchar column, not a numeric one. It contained numeric values in the sample I gave by coincidence, as there are some values that have other characters, so I don't believe a grouped sum would work here, would it?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 15:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855572#M338117</guid>
      <dc:creator>aazzarello</dc:creator>
      <dc:date>2023-01-25T15:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Create table where none of a given primary key match a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855578#M338120</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432394"&gt;@aazzarello&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My mistake. I did not include that the login column is a varchar column, not a numeric one. It contained numeric values in the sample I gave by coincidence, as there are some values that have other characters, so I don't believe a grouped sum would work here, would it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The sum in the suggested solution is totaling the results of the comparison: (login_id ^='NULL'). SAS returns a 1 for true and 0 for false.&lt;/P&gt;
&lt;P&gt;So the value of the variable isn't summed, the value of the comparison result is summed and does not matter as to the variable type as long as the comparison is valid for the variable.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 15:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855578#M338120</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-25T15:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Create table where none of a given primary key match a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855579#M338121</link>
      <description>&lt;P&gt;Did you even try the code? It recognizes that LOGIN_ID is character. I would explain, except&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;already has explained.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 17:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855579#M338121</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-25T17:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Create table where none of a given primary key match a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855599#M338134</link>
      <description>&lt;P&gt;I would try to do it something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
  select distinct name,login_id as login_id_3_1
  from work.names base
  where not exists(select * from work.names test 
                    where name=base.name and login_id is not null);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just one question: what do you need the LOGIN_ID for, if you already know that is always NULL?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 16:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Create-table-where-none-of-a-given-primary-key-match-a/m-p/855599#M338134</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-01-25T16:52:23Z</dc:date>
    </item>
  </channel>
</rss>

