<?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: delete columns if they are empty in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290271#M59728</link>
    <description>There are at least 10 threads on communities that deals with this issue. Just do a search.</description>
    <pubDate>Mon, 08 Aug 2016 18:18:12 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-08-08T18:18:12Z</dc:date>
    <item>
      <title>delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290221#M59716</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I used proc import and get datasets a and b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;PROC IMPORT OUT= WORK.auto&amp;amp;i DATAFILE= "C:\auto\&amp;amp;&amp;amp;price&amp;amp;i.xlsx"&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DBMS=xlsx REPLACE;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SHEET="auto";&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GETNAMES=YES;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;RUN;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and i get two datasets as below&amp;nbsp; and how to delete the columns which are empty like C,D,E,F,G,H from auto1and column D in auto2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Auto1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Zone&lt;/TD&gt;&lt;TD&gt;pricing&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;G&lt;/TD&gt;&lt;TD&gt;H&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;876231&lt;/TD&gt;&lt;TD&gt;1428&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;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;650123&lt;/TD&gt;&lt;TD&gt;1556&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;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&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;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 15:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290221#M59716</guid>
      <dc:creator>hexx18</dc:creator>
      <dc:date>2016-08-08T15:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290237#M59721</link>
      <description>&lt;P&gt;Welcome to the wonderful word of Excel and poor data results.&lt;/P&gt;
&lt;P&gt;You could drop the variables for any purpose. Or if you really want a new data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data work.want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set work.auto1 (drop=C D E F G H);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 16:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290237#M59721</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-08T16:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290255#M59724</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I am running in a loop if i drop C column when i running i a loop i will not have C column in Auto2 also right but i want that column in Auto2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to write code n0284330in such a way that it drops the empty columns automatically from each dataset while creating the output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so that&amp;nbsp;the same code used for &amp;nbsp;Auto1 it will drop CD EFGH&lt;/P&gt;&lt;P&gt;and for Auto2 it will drop D&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone pls help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 17:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290255#M59724</guid>
      <dc:creator>hexx18</dc:creator>
      <dc:date>2016-08-08T17:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290271#M59728</link>
      <description>There are at least 10 threads on communities that deals with this issue. Just do a search.</description>
      <pubDate>Mon, 08 Aug 2016 18:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290271#M59728</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-08-08T18:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290280#M59731</link>
      <description>&lt;P&gt;If one really wants to automate a process then using Excel as a data source and Proc import to read the data are two suboptimal choices.&lt;/P&gt;
&lt;P&gt;Excel in the form of XLSX or XLS files has no actual structure and manipulation of files can creat "phantom" variables and rows of data as you are experiencing.&lt;/P&gt;
&lt;P&gt;Proc Import has to guess every single time a file is read as to the types of data and characteristics. Using default settings for proc import and Excel spreadsheets you can get different data types just by changing the sort order of the data before proc import.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If these files are supposed to contain the same data it may be worth the effort to convert the XLSX to CSV and write, or modify the program creatd by proc import for one file, a custom program to read in a consistent manner.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 19:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290280#M59731</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-08T19:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290365#M59735</link>
      <description>&lt;PRE&gt;
The simplest way is using proc freq+nlevels, if you want more flexibilty ,try SQL.

data have;
 set sashelp.class;
 call missing(sex,age);
 if _n_=3 then call missing(weight);
 run;
 
ods select none;
ods output nlevels=temp;
proc freq data=have nlevels;
 tables _all_;
run;
proc sql;
 select tablevar into : drop separated by ','
  from temp
   where NNonMissLevels=0;
   
  alter table have
   drop &amp;amp;drop; 
quit;
 

&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Aug 2016 03:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290365#M59735</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-09T03:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290370#M59736</link>
      <description>&lt;P&gt;If you use a textual file format and a data step for the transfer, the data step specifies the columns. Any Excel-typical "extras" are automatically dropped.&lt;/P&gt;
&lt;P&gt;Proc Import is nice for tests, but should never be used in production-stage programs.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2016 11:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/290370#M59736</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-29T11:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/912458#M83253</link>
      <description>&lt;P&gt;I have tried the proc freq approach yet encountered the following error&lt;/P&gt;
&lt;P&gt;ERROR: Not enough memory for all variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;context: We have to use a standardized template table which is large, 138 columns, and I want to remove unused columns for a specific export.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there another approach to this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2024 15:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/912458#M83253</guid>
      <dc:creator>KoVa</dc:creator>
      <dc:date>2024-01-22T15:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/912466#M83254</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288016"&gt;@KoVa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have tried the proc freq approach yet encountered the following error&lt;/P&gt;
&lt;P&gt;ERROR: Not enough memory for all variables.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How many rows in the data set? What is the PROC FREQ code you are using?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2024 15:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/912466#M83254</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-22T15:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/912538#M83255</link>
      <description>&lt;P&gt;just a quick test table with about 8-9000 rows, but some columns are containing unique id's, so I think that's why the proc freq runs out of memory.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used the exact code from above, only changed it to my table. .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
 set sashelp.class;
 call missing(sex,age);
 if _n_=3 then call missing(weight);
 run;
 
ods select none;
ods output nlevels=temp;
proc freq data=have nlevels;
 tables _all_;
run;
proc sql;
 select tablevar into : drop separated by ','
  from temp
   where NNonMissLevels=0;
   
  alter table have
   drop &amp;amp;drop; 
quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2024 19:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/912538#M83255</guid>
      <dc:creator>KoVa</dc:creator>
      <dc:date>2024-01-22T19:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/912543#M83256</link>
      <description>&lt;P&gt;update: I found this macro with a proc freq but a bit different, which worked fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro findmiss(ds,macvar);
%local noteopt;
%let noteopt=%sysfunc(getoption(notes));
option nonotes;
*ds is the data set to parse for missing values;
*macvar is the macro variable that will store the list of empty columns;
%global &amp;amp;macvar; 
proc format;
  value nmis  .-.z =' ' other='1';
  value $nmis ' '=' ' other='1';
run;
ods listing close;
ods output OneWayFreqs=OneValue(
  where=(frequency=cumfrequency 
  AND CumPercent=100));

proc freq data=&amp;amp;ds;
  table _All_ / Missing ;
  format _numeric_ nmis. 
        _character_ $nmis.;
  run;
ods listing;
data missing(keep=var);
  length var $32.;
  set OneValue end=eof;
    if percent eq 100 AND sum(of F_:) &amp;lt; 1 ;
    var = scan(Table,-1,' ');
run;
proc sql noprint;
  select var into: &amp;amp;macvar separated by " "
  from missing;quit;
option &amp;amp;noteopt.;
%mend;

%findmiss(mydata,droplist); /*generate the list of empty columns */


data new;
  set mydata(drop=&amp;amp;droplist);
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2024 19:55:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/912543#M83256</guid>
      <dc:creator>KoVa</dc:creator>
      <dc:date>2024-01-22T19:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: delete columns if they are empty</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/912579#M83257</link>
      <description>&lt;P&gt;I think you must have too many levels/values in some variable,&lt;/P&gt;
&lt;P&gt;You could try PROC SQL way,that would get you faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
 call missing(sex,age);
 if _n_=3 then call missing(weight);
 run;
 



proc transpose data=have(obs=0) out=vnames;
var _all_;
run;
proc sql noprint;
select cat('n(',_NAME_,') as ',_NAME_) into :vnames separated by ',' from vnames;
create table temp as
select &amp;amp;vnames. from have;
quit;
proc transpose data=temp out=temp2;
var _all_;
run;
proc sql noprint;
select _NAME_ into :drops separated by ',' from temp2 where col1=0;
alter table have
 drop &amp;amp;drops.;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jan 2024 01:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/delete-columns-if-they-are-empty/m-p/912579#M83257</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-01-23T01:21:32Z</dc:date>
    </item>
  </channel>
</rss>

