<?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 How do i use an array to count up the values in this situation? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896482#M354227</link>
    <description>&lt;P&gt;Hello, the purpose of this is data manipulation practice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to use an array to count up the X's in the val1, val2, val3 variables. I'm trying to count across.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=",";
 	input subject $ val1 $ val2 $ val3 $;
 datalines;
 001, x, , ,
 002, x, x, ,
 003, x, , , 
 004, , , ,
 005, x, x, x
 ; 
 run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;results should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;subject sum&lt;/P&gt;
&lt;P&gt;001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;005&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Sep 2023 17:12:42 GMT</pubDate>
    <dc:creator>Hello_there</dc:creator>
    <dc:date>2023-09-29T17:12:42Z</dc:date>
    <item>
      <title>How do i use an array to count up the values in this situation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896482#M354227</link>
      <description>&lt;P&gt;Hello, the purpose of this is data manipulation practice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to use an array to count up the X's in the val1, val2, val3 variables. I'm trying to count across.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=",";
 	input subject $ val1 $ val2 $ val3 $;
 datalines;
 001, x, , ,
 002, x, x, ,
 003, x, , , 
 004, , , ,
 005, x, x, x
 ; 
 run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;results should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;subject sum&lt;/P&gt;
&lt;P&gt;001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;005&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 17:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896482#M354227</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-09-29T17:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use an array to count up the values in this situation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896485#M354228</link>
      <description>&lt;P&gt;No need for an array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  sum = 3 - cmiss(of var1-var3);
  keep subject sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Sep 2023 17:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896485#M354228</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-29T17:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use an array to count up the values in this situation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896486#M354229</link>
      <description>Thanks for the quick solution. I would like to use an array bc it would make it more flexible for when i re run the code for different variable amounts.</description>
      <pubDate>Fri, 29 Sep 2023 17:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896486#M354229</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-09-29T17:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use an array to count up the values in this situation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896493#M354233</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks for the quick solution. I would like to use an array bc it would make it more flexible for when i re run the code for different variable amounts.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That would allow you to use the DIM() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array list var1-var3;
sum=dim(list)-cmiss(of list[*]);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Sep 2023 17:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896493#M354233</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-29T17:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use an array to count up the values in this situation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896494#M354234</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks for the quick solution. I would like to use an array bc it would make it more flexible for when i re run the code for different variable amounts.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Provide a more realistic set of values then. And maybe variable names. Many of the functions that do some of this sort of stuff will work with a variable list, such as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; 's CMISS example.&lt;/P&gt;
&lt;P&gt;There are functions that work well for single character values in a similar manner, Countc. But if you specific words then examples are needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The basic approach if you really need to examine each value is going to look like:&lt;/P&gt;
&lt;PRE&gt;Counter=0;
do i= 1 to dim(arrayname);
   counter = sum(counter,&amp;lt;condition involving arrayname[i]&amp;gt;);
end;&lt;/PRE&gt;
&lt;P&gt;What that condition may look like depends a whole lot on the values.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 17:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896494#M354234</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-29T17:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use an array to count up the values in this situation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896496#M354236</link>
      <description>Brilliant!</description>
      <pubDate>Fri, 29 Sep 2023 17:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896496#M354236</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-09-29T17:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use an array to count up the values in this situation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896497#M354237</link>
      <description>Understandable.&lt;BR /&gt;&lt;BR /&gt;For my use case, the example i provided is the general structure of the problem i encounter a lot. The only things that needs to change is the amount of variables i put in the array. &lt;BR /&gt;&lt;BR /&gt;That being said, i will consider your approach also. Thanks</description>
      <pubDate>Fri, 29 Sep 2023 17:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-an-array-to-count-up-the-values-in-this-situation/m-p/896497#M354237</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2023-09-29T17:51:41Z</dc:date>
    </item>
  </channel>
</rss>

