<?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 Ignoring empty variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274771#M54883</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have some variables in my dataset that doesn't have any data at all. can someone tell me how do I ignore them during the import stage or any other data step? Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;PROC IMPORT DATAFILE="C:\DATA\havexlsx"&lt;BR /&gt;DBMS=xlsx replace&lt;BR /&gt;OUT=Apple.want;&lt;BR /&gt;SHEET='sheet1';&lt;BR /&gt;RUN;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jun 2016 19:25:27 GMT</pubDate>
    <dc:creator>mlogan</dc:creator>
    <dc:date>2016-06-02T19:25:27Z</dc:date>
    <item>
      <title>Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274771#M54883</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have some variables in my dataset that doesn't have any data at all. can someone tell me how do I ignore them during the import stage or any other data step? Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;PROC IMPORT DATAFILE="C:\DATA\havexlsx"&lt;BR /&gt;DBMS=xlsx replace&lt;BR /&gt;OUT=Apple.want;&lt;BR /&gt;SHEET='sheet1';&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2016 19:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274771#M54883</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-06-02T19:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274820#M54892</link>
      <description>&lt;P&gt;What do you mean by "ignore"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Missing values are ignored when calculations, such a avverage, are made.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want want to remove the column from the data set? This is dangerous as there might be some data when you import refreshed versions of the file later on, and you then end up with different table structures, and with code must deal with columns that may exist&amp;nbsp;or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2016 21:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274820#M54892</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-02T21:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274822#M54893</link>
      <description>&lt;P&gt;I've used this in the past:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample &lt;I&gt;24612: &lt;/I&gt;Delete variables that have only missing values&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/612.html" target="_blank"&gt;http://support.sas.com/kb/24/612.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;See "Full Code" tab for code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many alternatives to find on the www (but make sure these programs do exactly what you want in all circumstances!).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2016 21:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274822#M54893</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2016-06-02T21:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274829#M54896</link>
      <description>&lt;P&gt;Or a very crude:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data Apple.want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set Apple.want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; drop VarB VarQ VarX;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know the names of the variables you don't want put them in place of the VarB VarQ VarX.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2016 22:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274829#M54896</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-02T22:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274833#M54897</link>
      <description>I wanted to ignore the columns that completely null</description>
      <pubDate>Fri, 03 Jun 2016 00:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274833#M54897</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-06-03T00:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274834#M54898</link>
      <description>I need a code which will be dynamic</description>
      <pubDate>Fri, 03 Jun 2016 00:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274834#M54898</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-06-03T00:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274841#M54901</link>
      <description>&lt;P&gt;Tedious but simple to do with a _null_ data step. An example with sashelp.cars&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set sashelp.cars;
call missing (Origin, Cylinders); /* Make them all missing */
run;

data _null_;
set test end=done;
array _n _numeric_ _dumn;
array _c _character_ _dumc;
array _nn{2000} _temporary_;
array _nc{2000} _temporary_;
do i = 1 to dim(_n)-1;
    if not _nn{i} and not missing(_n{i}) then _nn{i} = 1;
    end;
do i = 1 to dim(_c)-1;
    if not _nc{i} and not missing(_c{i}) then _nc{i} = 1;
    end;
length _vars $1000;
if done then do;
    do i = 1 to dim(_n)-1;
        if not _nn{i} then _vars = catx(" ", _vars, vname(_n{i}));
        end;
    do i = 1 to dim(_c)-1;
        if not _nc{i} then _vars = catx(" ", _vars, vname(_c{i}));
        end;
    call symputx("droplist", _vars);
    end;
run;

data test2;
_dummy = 0; /* In case the drop list is empty */
set test;
drop &amp;amp;droplist _dummy;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jun 2016 02:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274841#M54901</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-03T02:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274842#M54902</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  do i=1 to 12;
    'VARlkj-- *&amp;amp;^*&amp;amp;^,'n = ' ';
    output; 
  end; 
run;
                      
proc sql noprint;

  select NAME into :var_list separated by '\'
  from DICTIONARY.COLUMNS 
  where LIBNAME='WORK' and MEMNAME='HAVE';

  select catx(' ',
         %macro loop_vars;
         %local i ;
         %do i=1 %to %sysfunc(countw(%superq(var_list),\));
         %if &amp;amp;i&amp;gt;1 %then ,;
          missing(max("%scan(%superq(var_list),&amp;amp;i,\)"n)) 
         %end;
         %mend; %loop_vars
         )
         into :missing_flag_list 
         from HAVE
         ;                   

  create table WANT as 
  select *
  from HAVE(drop=
         %macro loop_vars;
         %local i ;
         %do i=1 %to %sysfunc(countw(%superq(var_list),\));
          %if %scan(&amp;amp;missing_flag_list,&amp;amp;i) %then "%scan(%superq(var_list),&amp;amp;i,\)"n  ;
         %end;
         %mend; %loop_vars
        )
  ;

quit;  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jun 2016 03:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274842#M54902</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-03T03:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274883#M54913</link>
      <description>&lt;P&gt;Why is that? &amp;nbsp;It sounds to me like you don't know your own data then. &amp;nbsp;What does the data transfer agreement say? &amp;nbsp;Does that allow missing columns? &amp;nbsp;Don't have one of those, well that is the problem. &amp;nbsp;Your trying to guess what the data is without knowing the file strcuture or the contents, fix the process (i.e. do it properly in a documented manner using appropriate file formats and processes) and these problems dissappear.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 08:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274883#M54913</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-03T08:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274987#M54939</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;, I agree with your evaluation of spreadsheets as databases. But not everyone uses SAS within a &lt;EM&gt;process&lt;/EM&gt;. Some are data buyers and consumers, but others are just gleaners. Research and journalism, for example, often have no control over the structure&amp;nbsp;of the data that they gather.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 15:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/274987#M54939</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-03T15:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/275034#M54949</link>
      <description>&lt;P&gt;It is probably easier to use the NLEVELS option on PROC FREQ than using the older macros that have been around for years.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set sashelp.class ;
 no_number=.;
 no_character=' ';
run;

ods exclude nlevels;
ods output nlevels=nlevels;
proc freq nlevels data=test;
 tables _all_ / noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then get the list of variable names that are all missing from the NLEVELS dataset. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select tablevar into :droplist separated by ' '
  from nlevels
  where nnonmisslevels=0
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could do the reserve and get the list of variables that have non-missing data.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 17:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/275034#M54949</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-06-03T17:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/275142#M54983</link>
      <description>Hi Tom,&lt;BR /&gt;Your code doesn't create a data set with the non missing variables. Am I missing something from your code??</description>
      <pubDate>Sat, 04 Jun 2016 02:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/275142#M54983</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-06-04T02:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/275144#M54984</link>
      <description>&lt;P&gt;Complete &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom﻿&lt;/a&gt;'s code with the last step from my program up there.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2016 02:51:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/275144#M54984</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-04T02:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: Ignoring empty variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/275148#M54987</link>
      <description>&lt;P&gt;Creating a new dataset without selected variables is just the simple case of writing a data step with a DROP statement in it. &amp;nbsp;The dynamic part is to have a method where the list of variables does not need to be hard coded. That is what the macro variable is for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  drop &amp;amp;droplist;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Jun 2016 03:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ignoring-empty-variables/m-p/275148#M54987</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-06-04T03:20:30Z</dc:date>
    </item>
  </channel>
</rss>

