<?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: frequency and counts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410095#M279596</link>
    <description>&lt;P&gt;Few notes will help you understand the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array testx test1-test5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is equivalent to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array testx {5} test1 test2 test3 test4 test5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then testx(2) points to test2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;vname&lt;/STRONG&gt; is a function that assigns the variable name of array member to a desired variable,&lt;/P&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name = trim(vname(testx(i)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when i=3 then vname(testx(3)) = 'test3'; - the name of the 3rd variable in the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Nov 2017 07:00:02 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-11-03T07:00:02Z</dc:date>
    <item>
      <title>frequency and counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410004#M279591</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp;test1&amp;nbsp; test2 test3 test5 test5&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp;&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to make a frequency table of the percentage of each test (test1-test5 )as a % from the total of all (tests that are 1) 1= is done 0 not done.&lt;/P&gt;&lt;P&gt;The table is like that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Tests&amp;nbsp; &amp;nbsp; count&amp;nbsp; &amp;nbsp; %&amp;nbsp; &amp;nbsp; Total&amp;nbsp;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;test1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;test2&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;test 3&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;test 4&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;test 5&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Total&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when I do proc freq I can get them all, I tried to make a group but some observations contribute more than one time to each test.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So each observation may have more than one test. so getting group didn't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you guide me how to do that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lamia&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 20:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410004#M279591</guid>
      <dc:creator>lamiaH</dc:creator>
      <dc:date>2017-11-02T20:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: frequency and counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410014#M279592</link>
      <description>&lt;P&gt;Create one more variable per line that will add to the number you need?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 21:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410014#M279592</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-02T21:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: frequency and counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410022#M279593</link>
      <description>&lt;P&gt;What would the output look like for the given example data?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 21:36:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410022#M279593</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-02T21:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: frequency and counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410050#M279594</link>
      <description>&lt;P&gt;Is that what you want&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input id   test1  test2 test3 test4 test5;
datalines;
1     1        1       0       1       0
2     0        0       1       0       0
3     0        1       0       1       1 
4     1        1       0       0       1
; run;

data want;
  set have end=eof;
        retain tot1-tot5 total;
        array testx test1-test5;
        array totx tot1-tot5;
        do i=1 to 5;
           totx(i) = sum(of totx(i) , testx(i));&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;           total  = sum(of total, testx(i));   /* alternative 1 */&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;       end; &lt;BR /&gt;       /* total = sum(of total, test1,test2,test3,test4,test5); /* alternative 2 */&lt;BR /&gt;       if eof then do; &lt;BR /&gt;          do i=1 to 5; &lt;BR /&gt;             name = trim(vname(testx(i))); &lt;BR /&gt;             count = totx(i); &lt;BR /&gt;             percent = totx(i) / total; &lt;BR /&gt;             output; &lt;BR /&gt;          end; &lt;BR /&gt;       end; &lt;BR /&gt;       keep name count percent total; &lt;BR /&gt;run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Nov 2017 01:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410050#M279594</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-03T01:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: frequency and counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410056#M279595</link>
      <description>&lt;P&gt;Thank you so much Shmuel for your reply. I know I need to do array but I'm not that good at doing them. I will try the code tomorrow and let you know of the results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lamia&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 02:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410056#M279595</guid>
      <dc:creator>lamiaH</dc:creator>
      <dc:date>2017-11-03T02:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: frequency and counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410095#M279596</link>
      <description>&lt;P&gt;Few notes will help you understand the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array testx test1-test5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is equivalent to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array testx {5} test1 test2 test3 test4 test5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then testx(2) points to test2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;vname&lt;/STRONG&gt; is a function that assigns the variable name of array member to a desired variable,&lt;/P&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name = trim(vname(testx(i)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when i=3 then vname(testx(3)) = 'test3'; - the name of the 3rd variable in the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 07:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410095#M279596</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-03T07:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: frequency and counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410243#M279597</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the code, it works well except the total didn't calculate correctly so the percent didn't show as well. the counts were shown correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;so in your code :&lt;/P&gt;&lt;P&gt;total=sum(of total, test1, test2,test3, test4, test5);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so is it sum (of totx instead of total or what )!!!, because the total showed only 1 for all !!!)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help, I appreciate it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Lamia&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 14:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410243#M279597</guid>
      <dc:creator>lamiaH</dc:creator>
      <dc:date>2017-11-03T14:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: frequency and counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410316#M279598</link>
      <description>&lt;P&gt;TOTAL is total of all tests (test1 to test5) of all the observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TOTX is a name of an array and you cannot use it for adding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I run my test with both alternatives and got the same result, with total=10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check your code again. If you have any issue, please post the last code you run&lt;/P&gt;
&lt;P&gt;with the results you got.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 16:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410316#M279598</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-03T16:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: frequency and counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410378#M279599</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thank you so much, I did the code and I got the results, correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help, I've couldn't done it without you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lamia&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 17:42:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/frequency-and-counts/m-p/410378#M279599</guid>
      <dc:creator>lamiaH</dc:creator>
      <dc:date>2017-11-03T17:42:02Z</dc:date>
    </item>
  </channel>
</rss>

