<?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: Filter out columns if they are not null for a where condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837428#M331098</link>
    <description>My Bad i drafted the title in a confusing way. I am looking out for a solution where i can build up a lookup table based on nmonref column which will carry which all columns which are populated against a nmonref. for eg, select all non null columns from table where nmonref='2000'.</description>
    <pubDate>Fri, 07 Oct 2022 15:35:01 GMT</pubDate>
    <dc:creator>khandelwalanmol</dc:creator>
    <dc:date>2022-10-07T15:35:01Z</dc:date>
    <item>
      <title>Filter out columns if they are not null for a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837367#M331073</link>
      <description>&lt;P&gt;I am trying to build a dataset containing all the column headers which are not null for a particular condition against a column.&lt;/P&gt;&lt;P&gt;example: here is my sample dataset. I have to create a lookup table containing the columns which are not null for individual nmonref column&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Sample dataset&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;nmonref&lt;/TD&gt;&lt;TD&gt;fi_transaction_id&lt;/TD&gt;&lt;TD&gt;account_reference_xid&lt;/TD&gt;&lt;TD&gt;client_xid&lt;/TD&gt;&lt;TD&gt;comment_strg&lt;/TD&gt;&lt;TD&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TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;fi_transaction_id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;account_reference_xid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;comment_strg&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;contact_method_xcd&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;This&amp;nbsp; sample data is in a warehouse, so i am restricted to use pass through SQL to create this lookup.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 12:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837367#M331073</guid>
      <dc:creator>khandelwalanmol</dc:creator>
      <dc:date>2022-10-07T12:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out columns if they are not null for a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837384#M331081</link>
      <description>&lt;P&gt;Sounds like this simple enough, if cumbersome, code is all you need.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct nmonref, 'fi_transaction_id' as varname from have where fi_transaction_id is not null
union 
select distinct nmonref, 'client_xid' as varname from have where client_xid is not null
....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the variable names change then if you have the list of variable names it is a simple code generation problem to generate that code from data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should also check if the database you are connected to has any SQL enhancements that might make it easier.&amp;nbsp; Something similar to PROC TRANSPOSE.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 13:20:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837384#M331081</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-07T13:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out columns if they are not null for a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837386#M331082</link>
      <description>the table contains about 120+ columns to be checked, so i am looking out for something dynamic by which i can create that lookup. And the total rows are about 10k+.</description>
      <pubDate>Fri, 07 Oct 2022 13:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837386#M331082</guid>
      <dc:creator>khandelwalanmol</dc:creator>
      <dc:date>2022-10-07T13:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out columns if they are not null for a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837391#M331085</link>
      <description>&lt;P&gt;The first method that comes to mind is creating a table nmonref and one of the 5 other variables (5 tables in total) and then append all the tables (group and sort as needed)&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 13:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837391#M331085</guid>
      <dc:creator>Mike_j</dc:creator>
      <dc:date>2022-10-07T13:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out columns if they are not null for a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837392#M331086</link>
      <description>&lt;P&gt;You might consider if SAS can do it for you.&amp;nbsp; PROC FREQ has a nice feature called NLEVELS in PROC FREQ.&amp;nbsp; You could use&amp;nbsp;nmonref as a by variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if you can adapt this code to your situation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output nlevels=nlevels;
proc freq data=sashelp.cars nlevels;
  by make;
  tables _all_ / noprint;
run;
ods select all;
proc print data=nlevels;
  where NNonMissLevels&amp;gt;0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Oct 2022 13:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837392#M331086</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-07T13:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out columns if they are not null for a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837418#M331095</link>
      <description>&lt;P&gt;I am having a hard time understanding how the body of your question has anything to do with the title.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;Filter out columns if they are not null for a where condition&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What does "filter out columns" mean?&lt;/P&gt;
&lt;P&gt;What is not null mean in this context?&amp;nbsp; Assuming by COLUMN you mean VARIABLE does this mean the variable is never missing?&amp;nbsp; Or just not all missing?&lt;/P&gt;
&lt;P&gt;And how does this have anything to do with a WHERE condition?&amp;nbsp; A WHERE condition to do what exactly?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 15:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837418#M331095</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-07T15:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out columns if they are not null for a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837428#M331098</link>
      <description>My Bad i drafted the title in a confusing way. I am looking out for a solution where i can build up a lookup table based on nmonref column which will carry which all columns which are populated against a nmonref. for eg, select all non null columns from table where nmonref='2000'.</description>
      <pubDate>Fri, 07 Oct 2022 15:35:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837428#M331098</guid>
      <dc:creator>khandelwalanmol</dc:creator>
      <dc:date>2022-10-07T15:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out columns if they are not null for a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837542#M331170</link>
      <description>&lt;P&gt;Besides of what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;proposes especially with using Proc Freq you can of course also use explicit pass-through SQL as this will allow you to take full advantage of database functionality.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How such code would need to look like depends on your database. Here an example for Oracle.&lt;BR /&gt;&lt;A href="https://community.oracle.com/tech/developers/discussion/619474/how-to-get-a-list-of-all-columns-that-have-null-values-in-all-the-rows" target="_blank" rel="noopener"&gt;https://community.oracle.com/tech/developers/discussion/619474/how-to-get-a-list-of-all-columns-that-have-null-values-in-all-the-rows&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're not using an "exotic" database then I'd expect some Internet search should return DB specific code that's already close to what you need.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Oct 2022 01:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-out-columns-if-they-are-not-null-for-a-where-condition/m-p/837542#M331170</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-10-09T01:27:04Z</dc:date>
    </item>
  </channel>
</rss>

