<?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 Dynamically Select Columns with Non-Null values After a Grouping in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500023#M133091</link>
    <description>&lt;P&gt;Is there a way to query a list of columns in a table that have a value other than null?&amp;nbsp; I’m working with metadata to include a list of columns that have data in them when grouped by a particular column.&amp;nbsp; E.g. group by school and only include in the output columns that have a non-null value in the grouping.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example Output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;College:&amp;nbsp;&amp;nbsp;&amp;nbsp; Variable&lt;/P&gt;
&lt;P&gt;School_A &amp;nbsp;&amp;nbsp;Gender&lt;/P&gt;
&lt;P&gt;School_A &amp;nbsp;&amp;nbsp;SAT&lt;/P&gt;
&lt;P&gt;School_A &amp;nbsp;&amp;nbsp;County&lt;/P&gt;
&lt;P&gt;School_B&amp;nbsp; &amp;nbsp;Gender&lt;/P&gt;</description>
    <pubDate>Fri, 28 Sep 2018 20:27:07 GMT</pubDate>
    <dc:creator>DavidPhillips2</dc:creator>
    <dc:date>2018-09-28T20:27:07Z</dc:date>
    <item>
      <title>Dynamically Select Columns with Non-Null values After a Grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500023#M133091</link>
      <description>&lt;P&gt;Is there a way to query a list of columns in a table that have a value other than null?&amp;nbsp; I’m working with metadata to include a list of columns that have data in them when grouped by a particular column.&amp;nbsp; E.g. group by school and only include in the output columns that have a non-null value in the grouping.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example Output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;College:&amp;nbsp;&amp;nbsp;&amp;nbsp; Variable&lt;/P&gt;
&lt;P&gt;School_A &amp;nbsp;&amp;nbsp;Gender&lt;/P&gt;
&lt;P&gt;School_A &amp;nbsp;&amp;nbsp;SAT&lt;/P&gt;
&lt;P&gt;School_A &amp;nbsp;&amp;nbsp;County&lt;/P&gt;
&lt;P&gt;School_B&amp;nbsp; &amp;nbsp;Gender&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 20:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500023#M133091</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2018-09-28T20:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically Select Columns with Non-Null values After a Grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500028#M133093</link>
      <description>&lt;P&gt;Here is a partial code example using SASHelp.cars.&amp;nbsp; I'm having a hard time completing the commented out pseudo code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/*query columns in sashelp.cars*/
data carsMetadata (keep=name); set sashelp.vcolumn;
where libname = 'SASHELP' and type = 'char' and memname = 'CARS';



run;

/*query columns in cars that have non-null values when grouped by Make*/
/*this part is what I am trying to work with*/
proc sql;
create table carsgrouping as 
select * from sashelp.cars
group by make

/* something on the lines of having distinct( count(*)) &amp;gt; 1;
/*join with CarsMetadata*/

quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 20:37:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500028#M133093</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2018-09-28T20:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically Select Columns with Non-Null values After a Grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500040#M133103</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just have to guess at your meaning, but perhaps the NLEVELS output of PROC FREQ is what you want?&amp;nbsp; With a BY statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class ;
 by sex;
run;
data HAVE ;
  set class;
  if sex='M' then call missing(height);
  else call missing(weight);
run;
ods output nlevels=nlevels;
proc freq data=HAVE nlevels ;
  by sex ;
  tables _all_ / noprint;
run;

data want ;
  if 0 then set have (keep=sex);
  length tablevar $32 nlevels nmisslevels nnonmisslevels 8;
  format nlevels nmisslevels nnonmisslevels comma12.;
  set nlevels;
run;

proc print data=WANT;
  where nnonmisslevels;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    Sex    tablevar         nlevels     nmisslevels    nnonmisslevels

  1     F      Name                  9               0                9
  2     F      Sex                   1               0                1
  3     F      Age                   5               0                5
  4     F      Height                9               0                9
  6     M      Name                 10               0               10
  7     M      Sex                   1               0                1
  8     M      Age                   6               0                6
 10     M      Weight               10               0               10&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 21:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500040#M133103</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-28T21:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically Select Columns with Non-Null values After a Grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500041#M133104</link>
      <description>&lt;P&gt;Tom, this is exactly what I was looking for.&amp;nbsp; &amp;nbsp;Thank you for your reply to my post.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 21:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500041#M133104</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2018-09-28T21:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically Select Columns with Non-Null values After a Grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500497#M133306</link>
      <description>&lt;P&gt;I'm running into an exception scenario when no columns in the table contain null values that column&amp;nbsp;nnonmisslevels is not created.&amp;nbsp; How can I check if this column exists or create the column in all cases.&amp;nbsp; Currently i have a where clause of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where nnonmisslevels &amp;gt; 0;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 18:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500497#M133306</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2018-10-01T18:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically Select Columns with Non-Null values After a Grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500534#M133322</link>
      <description>&lt;P&gt;That is why I had an extra data step with a LENGTH statement to make sure that those "optional" variables were actually created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if you are using a data step then you could use an&amp;nbsp;IF statement instead of a WHERE statement. The IF statement will test the data in the currently being generated data vector whereas the WHERE statement needs to find the variable in the dataset that is being read in.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 20:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-Select-Columns-with-Non-Null-values-After-a-Grouping/m-p/500534#M133322</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-01T20:30:55Z</dc:date>
    </item>
  </channel>
</rss>

