<?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 Empty vars in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5393#M464</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I'm looking for a simple solution to retrieve all variables from a data set which are empty for all observations.&lt;BR /&gt;
&lt;BR /&gt;
Anyone?</description>
    <pubDate>Wed, 07 Nov 2007 11:09:36 GMT</pubDate>
    <dc:creator>Rik</dc:creator>
    <dc:date>2007-11-07T11:09:36Z</dc:date>
    <item>
      <title>Empty vars</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5393#M464</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I'm looking for a simple solution to retrieve all variables from a data set which are empty for all observations.&lt;BR /&gt;
&lt;BR /&gt;
Anyone?</description>
      <pubDate>Wed, 07 Nov 2007 11:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5393#M464</guid>
      <dc:creator>Rik</dc:creator>
      <dc:date>2007-11-07T11:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Empty vars</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5394#M465</link>
      <description>SAS-L provides an excellent source for such challenges. It is accessible either as comp.soft-sys.sas in Google Groups  or at &lt;A href="http://www.listserv.uga.edu/archives/sas-l.html" target="_blank"&gt;http://www.listserv.uga.edu/archives/sas-l.html&lt;/A&gt;. These loosely mirror each other.&lt;BR /&gt;
&lt;BR /&gt;
A quick search in SAS-L archives or Google Group comp.soft-sys.sas for "empty columns" will return a thread from earlier this year.&lt;BR /&gt;
From discussions on SAS-L the most common method uses SQL to acquire the list of entirely-missing columns. &lt;BR /&gt;
The following code creates syntax to create a table with like-named columns and just one row, holding the count of rows where that column is non-missing. When the count is zero, the column is entirely missing. &lt;BR /&gt;
SQL does not support the missing() function because it already has &lt;B&gt; {column}  is null &lt;/B&gt;. &lt;BR /&gt;
I have created a test table in work.demo in which some character columns are entirely missing.&lt;BR /&gt;
In the code that follows the first SQL statement creates the "counting syntax". The second SQL statement then uses that to create the table of summary counts [pre]proc sql noprint ;                                            &lt;BR /&gt;
  select 'sum( not ' !! trim(name) !! ' is null ) as ' !! name&lt;BR /&gt;
    into :counters separated by ', '                          &lt;BR /&gt;
    from dictionary.columns                                   &lt;BR /&gt;
   where libname='WORK' and memname= 'DEMO'                   &lt;BR /&gt;
        ;                                                     &lt;BR /&gt;
  create table emptys as                                      &lt;BR /&gt;
  select &amp;amp;counters &lt;BR /&gt;
    from demo &lt;BR /&gt;
        ;                                &lt;BR /&gt;
quit;       [/pre]&lt;BR /&gt;
A common reason for creating this information is to build a fresh table excluding  the empty columns. The following code achieves that. [pre]proc transpose ; run;                              &lt;BR /&gt;
proc sql noprint ;                                 &lt;BR /&gt;
  select _name_ into :wanted separated by ', '     &lt;BR /&gt;
    from _last_ where col1 gt 0 &lt;BR /&gt;
        ;                  &lt;BR /&gt;
  create table reduced as select &amp;amp;wanted from demo;&lt;BR /&gt;
quit;    [/pre]&lt;BR /&gt;
Here proc transpose has taken the default options. It reads the latest dataset &lt;B&gt; work.emptys&lt;/B&gt;, which has just come out of proc sql. By Default it writes to the next dataset in the work.data{n} sequence. In the proc SQL that follows, the output from proc transpose is referred as _last_.&lt;BR /&gt;
&lt;BR /&gt;
Although such extended use of defaults may be deprecated by some, I find it helpful in reducing code to the more-relevant issues.&lt;BR /&gt;
&lt;BR /&gt;
Another $0.02&lt;BR /&gt;
from&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Wed, 07 Nov 2007 15:31:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5394#M465</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-07T15:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Empty vars</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5395#M466</link>
      <description>Some shorter code if you have SAS 9 : proc Freq does count how many non-missing distinct value each variable has, so just re-read these countings and build a list of unwanted variables. Then use the list in an ALTER TABLE ... DROP statement.&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA work.test ;&lt;BR /&gt;
   DO i = 1 TO 30 ;&lt;BR /&gt;
     x1 = i*2 ;&lt;BR /&gt;
     x2 = . ;&lt;BR /&gt;
     x3 = " " ;&lt;BR /&gt;
     x4 = PUT(i,Z2.) ;&lt;BR /&gt;
     OUTPUT ;&lt;BR /&gt;
   END ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
ODS OUTPUT nLevels = work.nValues ;&lt;BR /&gt;
PROC FREQ DATA = work.test NLEVELS ;&lt;BR /&gt;
   TABLES _ALL_ / NOPRINT ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
PROC SQL NOPRINT ;&lt;BR /&gt;
   SELECT tableVar &lt;BR /&gt;
         INTO : dropThoseVars SEPARATED BY ","&lt;BR /&gt;
   FROM work.nValues&lt;BR /&gt;
   WHERE nNonMissLevels = 0&lt;BR /&gt;
   ;&lt;BR /&gt;
   ALTER TABLE work.test &lt;BR /&gt;
         DROP &amp;amp;dropThoseVars ;&lt;BR /&gt;
QUIT ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Regards.&lt;BR /&gt;
Olivier</description>
      <pubDate>Wed, 07 Nov 2007 17:58:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5395#M466</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2007-11-07T17:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: Empty vars</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5396#M467</link>
      <description>Thank you Oliver&lt;BR /&gt;
&lt;BR /&gt;
That provides a very much simpler method of obtaining nMiss counts for character ( as well as numeric ) columns. &lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
&lt;BR /&gt;
PeterC&lt;BR /&gt;
&lt;BR /&gt;
P.S.&lt;BR /&gt;
my watch of the message returned the syntax in "fixed pitch" which made reading and understanding the code, much easier. White space and indentation are also  maintained on the posting.&lt;BR /&gt;
&lt;BR /&gt;
We can achieve the same effect on messages in the Forum. Place ["pre"] before code and ["/pre"] after ~~~ but without those quotes. &lt;BR /&gt;
Like: [pre]ODS OUTPUT nLevels= work.nValues ;&lt;BR /&gt;
PROC FREQ DATA= work.test NLEVELS ;&lt;BR /&gt;
  TABLES _ALL_ / NOPRINT ;&lt;BR /&gt;
run;[/pre]</description>
      <pubDate>Thu, 08 Nov 2007 08:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5396#M467</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-08T08:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Empty vars</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5397#M468</link>
      <description>Thanks Olivier,&lt;BR /&gt;
&lt;BR /&gt;
This is what I needed.&lt;BR /&gt;
There is 1 problem left with the solution that you propose and that is the output that’s created by the FREQ procedure. I receive hundreds of pages in my output window&lt;BR /&gt;
&lt;BR /&gt;
Any suggestion on how to avoid having this output? &lt;BR /&gt;
Specify the NOPRINT option in the PROC statement will result in terminating the FREQ procedure.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again for your help.&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Rik

Message was edited by: Rik</description>
      <pubDate>Thu, 08 Nov 2007 14:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5397#M468</guid>
      <dc:creator>Rik</dc:creator>
      <dc:date>2007-11-08T14:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Empty vars</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5398#M469</link>
      <description>Put an [pre] ODS Listing close ;[/pre] statement before the PROC FREQ statement.</description>
      <pubDate>Thu, 08 Nov 2007 14:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5398#M469</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-08T14:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: Empty vars</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5399#M470</link>
      <description>Problem solved!&lt;BR /&gt;
&lt;BR /&gt;
Thanks both for your help!</description>
      <pubDate>Thu, 08 Nov 2007 14:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Empty-vars/m-p/5399#M470</guid>
      <dc:creator>Rik</dc:creator>
      <dc:date>2007-11-08T14:49:17Z</dc:date>
    </item>
  </channel>
</rss>

