<?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 variables when all values are zero in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307347#M270608</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/112053"&gt;@lunarin﻿&lt;/a&gt;&amp;nbsp;Search the forum. There are several solutions on here that work. Are you interested in staying in IML?&lt;/P&gt;</description>
    <pubDate>Wed, 26 Oct 2016 09:55:06 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-10-26T09:55:06Z</dc:date>
    <item>
      <title>Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307324#M270600</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to programming in SAS. As part of a school project, i was tasked to do data cleaning for the following files: &lt;A href="https://www.kaggle.com/c/santander-customer-satisfaction/data" target="_blank"&gt;https://www.kaggle.com/c/santander-customer-satisfaction/data&lt;/A&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data has many variables that have no meaning (i.e. consists of only 0 values). I am wondering how can I write a code to remove these variables automatically? Do note I am completely new to SAS programming and I have tried to modify other solutions to fit my problem but to no avail. Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 07:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307324#M270600</guid>
      <dc:creator>lunarin</dc:creator>
      <dc:date>2016-10-26T07:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307325#M270601</link>
      <description>&lt;P&gt;Hi &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I Can't open any of the data you are linking to, can you post some sample data?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variables you would like to check for a 0 value are numeric right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 07:14:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307325#M270601</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-10-26T07:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307326#M270602</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://imgur.com/a/AtRzX" target="_blank"&gt;http://imgur.com/a/AtRzX&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It has over 100 columns with no serialized naming. Yes they are numeric. I am just not sure how to loop through each variable in SAS!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 07:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307326#M270602</guid>
      <dc:creator>lunarin</dc:creator>
      <dc:date>2016-10-26T07:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307329#M270603</link>
      <description>&lt;P&gt;OK so they are all numeric? no character variables?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 07:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307329#M270603</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-10-26T07:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307330#M270604</link>
      <description>Yes that is right&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Oct 2016 07:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307330#M270604</guid>
      <dc:creator>lunarin</dc:creator>
      <dc:date>2016-10-26T07:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307332#M270605</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
   use THENAMEOFYOURDATASET;
      read all var _ALL_ into X[colname=varNames]; 
   close THENAMEOFYOURDATASET;
   
   cols = ncol(X);

   sums = j(1,cols,0);

   do j = 1 to cols;
      sums[j] = sum(X[ ,j]);
   end;

   idx = loc(sums &amp;gt; 0); 

   newX = X[ ,idx];
   
   create MyData from newX[colname=varNames];
      append from newX;
   close MyData;

QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where of course you insert your dataset name instead of &amp;nbsp;&lt;CODE class=" language-sas"&gt;THENAMEOFYOURDATASET.. :)&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="http://sasnrd.com/" target="_blank"&gt;http://sasnrd.com/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2017 09:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307332#M270605</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-09-19T09:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307340#M270606</link>
      <description>&lt;P&gt;hi draycut,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you very much it worked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 08:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307340#M270606</guid>
      <dc:creator>lunarin</dc:creator>
      <dc:date>2016-10-26T08:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307343#M270607</link>
      <description>&lt;P&gt;Hi draycut,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Upon closer inspection, the data was actually modified and it removed variables who's sum is not zero.&lt;/P&gt;&lt;P&gt;What I want to achieve is to delete an ENTIRE variable IF all its values are zero. I am wondering if you could me with that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 09:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307343#M270607</guid>
      <dc:creator>lunarin</dc:creator>
      <dc:date>2016-10-26T09:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307347#M270608</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/112053"&gt;@lunarin﻿&lt;/a&gt;&amp;nbsp;Search the forum. There are several solutions on here that work. Are you interested in staying in IML?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 09:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307347#M270608</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-26T09:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307351#M270609</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x $ y z;
cards;
x 1 0
y 0 0
z 0 0
;
run;
data _null_;
 set sashelp.vcolumn(where=(libname='WORK' and memname='HAVE' and type='num')) end=last;
 if _n_=1 then call execute('proc sql;create table temp as select ');
 call execute(cat('sum(',name,' ne 0) as ',name));
 if last then call execute('from have;quit;');
  else call execute(',');
run;
proc transpose data=temp out=temp1;
run;
proc sql noprint;
select _name_ into : list separated by ' ' from temp1
 where col1=0;
quit;
data want;
 set have(drop=&amp;amp;list);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Oct 2016 10:48:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307351#M270609</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-26T10:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307353#M270610</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x $ y z zz;
cards;
x 1 0 0
y 0 0 0
z 0 0 0
;
run;
proc iml;
use have;
read all var _num_ into x[c=vnames];
close;

y=vnames[loc((x^=0)[+,]=0)];

submit y;
 data want;
  set have;
  drop &amp;amp;y;
 run;
endsubmit;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Oct 2016 10:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307353#M270610</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-26T10:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting variables when all values are zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307358#M270611</link>
      <description>&lt;P&gt;When you select which fields to remove, note that a sum of 0 is not a guarantee that all values are zero. &amp;nbsp;You would be better advised to use PROC SUMMARY to get the min and the max, and make sure both the min and the max are zero.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 11:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-variables-when-all-values-are-zero/m-p/307358#M270611</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-26T11:15:36Z</dc:date>
    </item>
  </channel>
</rss>

