<?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: deleting empty columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308058#M66046</link>
    <description>&lt;A href="https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290365#M59735" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290365#M59735&lt;/A&gt;</description>
    <pubDate>Sat, 29 Oct 2016 04:35:40 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-10-29T04:35:40Z</dc:date>
    <item>
      <title>deleting empty columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308045#M66036</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes I work with Excel files that contain empty columns, and when I import such files into SAS I get empty columns in the SAS table as well (SAS calls them F2, F13 etc depending on the empty columns' locations amidst the other non-empty columns).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible to automatically delete these empty columns or to not import them at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2016 00:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308045#M66036</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-10-29T00:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: deleting empty columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308046#M66037</link>
      <description>&lt;P&gt;Welcome to Excel anarchy where it will let you do most anything.....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try deleting the "Fnnn" columns in Excel just to the right of your named columns before you import. The same thing can happen with rows so do the same with those.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2016 01:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308046#M66037</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-10-29T01:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: deleting empty columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308052#M66041</link>
      <description>&lt;P&gt;Hi SASKiwi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the thing is that I might have dozens and even hundreds of columns and the empty columns can be hidden pretty much randomly, and I might have to import many such Excel files, so it will be preferable to have some automatic way of deleting these empty columns rather than manual.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2016 03:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308052#M66041</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-10-29T03:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: deleting empty columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308055#M66043</link>
      <description>&lt;P&gt;Doing some research I found that such a question already exists in the SAS communities.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a link:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290221#U290221" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290221#U290221&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The discussion is very interesting and instructive. I used KSharp's code in a macro and got the result that I wanted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) first I imported with proc import the data1-data10 that I needed.&lt;/P&gt;
&lt;P&gt;2)) then I deleted the empty columns in these data tables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro delete_empty;
%do i=1 %to 10;
ods select none;
ods output nlevels=temp;
proc freq data=data&amp;amp;i nlevels;
 tables _all_;
run;
proc sql;
 select tablevar into : drop separated by ','
  from temp
   where NNonMissLevels=0;
   
  alter table data&amp;amp;i
   drop &amp;amp;drop; 
quit;
%end;

%mend delete_empty;
%delete_empty&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2016 04:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308055#M66043</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-10-29T04:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: deleting empty columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308058#M66046</link>
      <description>&lt;A href="https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290365#M59735" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290365#M59735&lt;/A&gt;</description>
      <pubDate>Sat, 29 Oct 2016 04:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308058#M66046</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-29T04:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: deleting empty columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308060#M66047</link>
      <description>&lt;P&gt;If you just want to delete all columns in a SAS dataset where the name follows a pattern of "F&amp;lt;digits&amp;gt;" then below code would do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro drop_col_Fdigit(table);

  %let table=%upcase(&amp;amp;table);
  %local drop_list;
  %let drop_list=;

  proc sql noprint;
    select name into :drop_list separated by ','
    from dictionary.columns
    where 
      libname="%scan(WORK.&amp;amp;table,-2)" 
      and memname="%scan(WORK.&amp;amp;table,-1)" 
      and prxmatch('/^F\d+\s*$/oi',name)&amp;gt;0
    ;
  quit;

  %if %bquote(&amp;amp;drop_list) ne %bquote() %then
    %do;
      proc sql noprint;
        alter table &amp;amp;table
        drop &amp;amp;drop_list
        ;
      quit;
    %end;

%mend;


data imported;
  set sashelp.class;
  f5=.;
  b5=.;
  _f5=.;
  F123=' ';
  F5F=.;
  '5F'n=.;
  '5F5'n=.;
run;

%drop_col_Fdigit(work.imported);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Oct 2016 04:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308060#M66047</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-29T04:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: deleting empty columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308061#M66048</link>
      <description>&lt;P&gt;Hi KSharp,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks for the code! I would have accepted it as the solution if it was posted in my question!&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2016 04:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308061#M66048</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-10-29T04:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: deleting empty columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308063#M66050</link>
      <description>&lt;P&gt;Thanks Patrick, will come in handy!&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2016 04:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308063#M66050</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-10-29T04:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: deleting empty columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308067#M66053</link>
      <description>&lt;PRE&gt;

data have;
 set sashelp.class;
 call missing(name,age,weight);
run;

proc iml;
use have nobs nobs;
read all var _char_ into x[c=varname1];
read all var _num_ into y[c=varname2];
close;
miss1=varname1[loc(countmiss(x,'col')=nobs)];
miss2=varname2[loc(countmiss(y,'col')=nobs)];

submit miss1 miss2;
 data want;
  set have(drop=&amp;amp;miss1 &amp;amp;miss2);
 run;
endsubmit;
quit;


&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Oct 2016 05:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308067#M66053</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-29T05:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: deleting empty columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308112#M66069</link>
      <description>&lt;P&gt;Personal opinion: if you have to continually clean up what others have done in spreadsheets you have to deal with then I'd be worried about what else is happening in the populated sections. From personal experience I've had users change column headings, column locations, column types, data order - the list goes on and on - without realising the consequences of what they are doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the end of the day if you want reliable and robust data inputs from spreadsheets, then having a defined and agreed layout and an agreement to not change it without consultation is pretty much essential....end of rant.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2016 03:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308112#M66069</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-10-30T03:06:13Z</dc:date>
    </item>
  </channel>
</rss>

