<?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: Count the number of non-zero occurrences for a variable in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214234#M3090</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am only checking a handful of them.&amp;nbsp; They are not similarly named.&amp;nbsp; I think RW9's response did the trick.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 31 Jul 2015 14:30:37 GMT</pubDate>
    <dc:creator>bpearce</dc:creator>
    <dc:date>2015-07-31T14:30:37Z</dc:date>
    <item>
      <title>Count the number of non-zero occurrences for a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214226#M3082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I'm working with a very large data set (over 15 million observations and over 1000 variables). I would like to count the number of non-zero entries for a handful of variables from within my data set.&amp;nbsp; For example, in the table below VAR 1 has 3 occurrences, and VAR 2 has two occurrences.&amp;nbsp; I'm a beginner, so please provide some explanation if possible.&amp;nbsp; I appreciate any help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="149" style="border: 1px solid rgb(0, 0, 0); width: 336px; height: 125px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Client #&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Var 1&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Var 2&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;245&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2699&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3694&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;4&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1548&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;5&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3554&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jul 2015 14:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214226#M3082</guid>
      <dc:creator>bpearce</dc:creator>
      <dc:date>2015-07-30T14:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of non-zero occurrences for a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214227#M3083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have SAS IML, there is one really fast way to count missing/not missing.&lt;/P&gt;&lt;P&gt;Look at this post: &lt;A href="http://blogs.sas.com/content/iml/2011/09/19/count-the-number-of-missing-values-for-each-variable.html" title="http://blogs.sas.com/content/iml/2011/09/19/count-the-number-of-missing-values-for-each-variable.html"&gt;http://blogs.sas.com/content/iml/2011/09/19/count-the-number-of-missing-values-for-each-variable.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have HP procs and a grid license? That is another route.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps,&lt;/P&gt;&lt;P&gt;Miguel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jul 2015 14:20:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214227#M3083</guid>
      <dc:creator>M_Maldonado</dc:creator>
      <dc:date>2015-07-30T14:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of non-zero occurrences for a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214228#M3084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm sure there will be some good array solutions, but this is the first thing that came to mind.&amp;nbsp; If it is only a handful of variables it's a viable solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;infile cards dsd;&lt;/P&gt;&lt;P&gt;input Client Var1 Var2;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1,245,2699&lt;/P&gt;&lt;P&gt;2,0,0&lt;/P&gt;&lt;P&gt;3,3694,0&lt;/P&gt;&lt;P&gt;4,1548,0&lt;/P&gt;&lt;P&gt;5,0,3554&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;count = sum((var1 ne 0)+(var2 ne 0));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jul 2015 14:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214228#M3084</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-07-30T14:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of non-zero occurrences for a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214229#M3085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, you can use arrays.&amp;nbsp; This would be preferred if there were many variables.&amp;nbsp; &lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; client=1; var1=245; var2=2696; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; client=2; var1=0; var2=0; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=i);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array list{*} var1 var2;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; count_miss=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to dim(list);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if list{i}=0 then count_miss=sum(count_miss,1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;If they all have the same prefix then its even easier:&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;data want (drop=i);&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&amp;nbsp; array var{*};&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&amp;nbsp; count_miss=0;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&amp;nbsp; do i=1 to dim(var);&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if var{i}=0 then count_miss=sum(count_miss,1);&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jul 2015 14:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214229#M3085</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-30T14:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of non-zero occurrences for a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214230#M3086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;RW9, I'm a beginner at arrays.&amp;nbsp; I ran what you have and get the following error.&amp;nbsp; Can you assist?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;22&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;GOPTIONS ACCESSIBLE;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;data want2 (drop=i);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;set have;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;25&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;array var{*};&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;ERROR: The array var has been defined with zero elements.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;26&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;count_miss=0;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;27&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;do i=1 to dim(var);&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;if var{i}=0 then count_miss=sum(count_miss,1);&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;ERROR: Too many array subscripts specified for array var.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;29&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;end;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;run;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jul 2015 14:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214230#M3086</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-07-30T14:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of non-zero occurrences for a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214231#M3087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi RW9,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ran the code, but I'm not getting what I had hoped for.&amp;nbsp; The code ran the number of misses (zero values), by row.&amp;nbsp; For example, client 1 would have 0 misses and client 2 would have 2 misses.&amp;nbsp; However, I want the total number of times each variable (column) has a value.&amp;nbsp; In my real data set, I have over 15 million clients and 1000 variables. I want separate totals for each variable, so variable 1 would have 8 million occurrences and variable 2 would have 9 million (as an example).&amp;nbsp; Can you help me modify the code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 13:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214231#M3087</guid>
      <dc:creator>bpearce</dc:creator>
      <dc:date>2015-07-31T13:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of non-zero occurrences for a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214232#M3088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I thought you were checking "a handful" of variables.&amp;nbsp; Do you need to check 1000 now?&amp;nbsp; If so are they similarly named, as in VAR1 VAR2...VAR1000?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 13:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214232#M3088</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-07-31T13:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of non-zero occurrences for a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214233#M3089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, ok, so you want to check if the sum per column is 0.&amp;nbsp; Then your best off checking one of the procedures associated with that.&amp;nbsp; Proc means, or proc summary.&amp;nbsp; Say:&lt;/P&gt;&lt;P&gt;proc means data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var var1-var1000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output out=results mean=mean;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then if the resulting mean for the variable is 0 you know they are all zeroes.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 14:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214233#M3089</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-31T14:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of non-zero occurrences for a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214234#M3090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am only checking a handful of them.&amp;nbsp; They are not similarly named.&amp;nbsp; I think RW9's response did the trick.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 14:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214234#M3090</guid>
      <dc:creator>bpearce</dc:creator>
      <dc:date>2015-07-31T14:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of non-zero occurrences for a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214235#M3091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A different approach:&lt;/P&gt;&lt;P&gt;Use a custom format to identify ranges of values of interest. This one treats every non-missing value except 0 as nonzero and shows 0 as such.&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;value nonzero&lt;/P&gt;&lt;P&gt;low - &amp;lt;0, 0&amp;lt;-high = 'Non-zero'&lt;/P&gt;&lt;P&gt;0 = 'Zero';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;_numeric_ is a special variable list identifier that says to do what ever for all numeric variables. So can be a short hand for large lists.&lt;/P&gt;&lt;P&gt;Using proc freq and the format will give you nonzero and zero counts and percentages for each variable plus the missing by default.&lt;/P&gt;&lt;P&gt;proc freq data=have;&lt;/P&gt;&lt;P&gt;tables _numeric_;&lt;/P&gt;&lt;P&gt;format _numeric_ nonzero. ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 14:37:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Count-the-number-of-non-zero-occurrences-for-a-variable/m-p/214235#M3091</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-31T14:37:51Z</dc:date>
    </item>
  </channel>
</rss>

