<?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 loops to update allocation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/loops-to-update-allocation/m-p/475284#M122204</link>
    <description>&lt;P&gt;I have a data that kind of looks like this: I have 2310 subjects, 3 Treatments(1,2,3) and The variable X which is X(Age factor, Treatment) so X12 would be age factor 1 and treatment 2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data have;
input  Subject  Treatment X;
datalines;
 1            1     X12
 2            2     X12
 3            3     X13
 4            1     X11
 5            2     X13
 6            3     X12
 7            1     X11
 8            2     X12
 9            1     X11
 10           3     X13&lt;BR /&gt;.......................&lt;BR /&gt;2310          3    X12
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have to count the number of X's using the variable Z so Z11=#of X11's , Z12=#of X12's and so on but if the last number in the X and T is the same then you add one to the allocation.&lt;/P&gt;&lt;P&gt;So Z11=X11+1 if T=1, Z12=X12+1 If T=2 and Z13=X13+1 if T=3.&amp;nbsp; If last number of X and T don't correspond to each other then it would stay the same:&lt;/P&gt;&lt;P&gt;Z11=X11,if T=2 or T=3&lt;/P&gt;&lt;P&gt;Z12=X12 if T=2 or T=1&lt;/P&gt;&lt;P&gt;Z13=Z13. if T=1 or T=2&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I also have to define a function where&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;M1=std(Z11,Z12,Z13) where T=1 and Z11=Z11+1&lt;/P&gt;&lt;P&gt;M2=std(Z11,Z12,Z13) where T=2 and Z12=Z12+1&lt;/P&gt;&lt;P&gt;M3=std(Z11,Z12,Z13) where T=3 and Z13=Z13+1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In the end my result should look like this:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Z11 Z12 Z13 Z21 Z22 Z23 Z31 Z32 Z33&lt;/P&gt;&lt;P&gt;20&amp;nbsp; &amp;nbsp;25&amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; 15&amp;nbsp; 18&amp;nbsp; &amp;nbsp; 19&amp;nbsp; 30&amp;nbsp; &amp;nbsp; 25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;G1:263&lt;/P&gt;&lt;P&gt;G2:212&lt;/P&gt;&lt;P&gt;G3:258&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have this is the code I have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data count;
set dynamic;
z11=0;
z12=0;
z13=0;
if Y="X11" then do;
z11=z11+1;
if T=1 then Z11=Z11+1;;
end;
else if Y="X12" then do;
z12=z12+1;
if T=2 then Z12=Z12+1;
end;
else if Y="X13" then do;
z13=z13+1;
if T=3 then z13=z13+1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am having trouble on how to figure out the function in the code above as I would need the counts of Z11 when T=1 and Z11 when T is not equal to 1. Any help would be appreciated.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Jul 2018 18:08:11 GMT</pubDate>
    <dc:creator>azt5173</dc:creator>
    <dc:date>2018-07-03T18:08:11Z</dc:date>
    <item>
      <title>loops to update allocation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loops-to-update-allocation/m-p/475284#M122204</link>
      <description>&lt;P&gt;I have a data that kind of looks like this: I have 2310 subjects, 3 Treatments(1,2,3) and The variable X which is X(Age factor, Treatment) so X12 would be age factor 1 and treatment 2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data have;
input  Subject  Treatment X;
datalines;
 1            1     X12
 2            2     X12
 3            3     X13
 4            1     X11
 5            2     X13
 6            3     X12
 7            1     X11
 8            2     X12
 9            1     X11
 10           3     X13&lt;BR /&gt;.......................&lt;BR /&gt;2310          3    X12
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have to count the number of X's using the variable Z so Z11=#of X11's , Z12=#of X12's and so on but if the last number in the X and T is the same then you add one to the allocation.&lt;/P&gt;&lt;P&gt;So Z11=X11+1 if T=1, Z12=X12+1 If T=2 and Z13=X13+1 if T=3.&amp;nbsp; If last number of X and T don't correspond to each other then it would stay the same:&lt;/P&gt;&lt;P&gt;Z11=X11,if T=2 or T=3&lt;/P&gt;&lt;P&gt;Z12=X12 if T=2 or T=1&lt;/P&gt;&lt;P&gt;Z13=Z13. if T=1 or T=2&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I also have to define a function where&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;M1=std(Z11,Z12,Z13) where T=1 and Z11=Z11+1&lt;/P&gt;&lt;P&gt;M2=std(Z11,Z12,Z13) where T=2 and Z12=Z12+1&lt;/P&gt;&lt;P&gt;M3=std(Z11,Z12,Z13) where T=3 and Z13=Z13+1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In the end my result should look like this:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Z11 Z12 Z13 Z21 Z22 Z23 Z31 Z32 Z33&lt;/P&gt;&lt;P&gt;20&amp;nbsp; &amp;nbsp;25&amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; 15&amp;nbsp; 18&amp;nbsp; &amp;nbsp; 19&amp;nbsp; 30&amp;nbsp; &amp;nbsp; 25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;G1:263&lt;/P&gt;&lt;P&gt;G2:212&lt;/P&gt;&lt;P&gt;G3:258&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have this is the code I have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data count;
set dynamic;
z11=0;
z12=0;
z13=0;
if Y="X11" then do;
z11=z11+1;
if T=1 then Z11=Z11+1;;
end;
else if Y="X12" then do;
z12=z12+1;
if T=2 then Z12=Z12+1;
end;
else if Y="X13" then do;
z13=z13+1;
if T=3 then z13=z13+1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am having trouble on how to figure out the function in the code above as I would need the counts of Z11 when T=1 and Z11 when T is not equal to 1. Any help would be appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 18:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loops-to-update-allocation/m-p/475284#M122204</guid>
      <dc:creator>azt5173</dc:creator>
      <dc:date>2018-07-03T18:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: loops to update allocation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loops-to-update-allocation/m-p/475361#M122236</link>
      <description>&lt;P&gt;Can you post the expected result of the data you posted?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc summary is my first choice, when things have to be counted. If i understood the rules you have to apply, then the z??-counter is increased if substr(x, 3, 1) = Treatment. That rule can be used in a where statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Subject Treatment  X $;
datalines;
 1 1 X12
 2 2 X12
 3 3 X13
 4 1 X11
 5 2 X13
 6 3 X12
 7 1 X11
 8 2 X12
 9 1 X11
 10 3 X13
 ;
 run;

proc summary data=have(where=(put(Treatment, 1.) = substr(x, 3, 1))) nway;
   class x;
   output out=work.counted(drop= _type_ rename=(_freq_ = count));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Things to do: change x to z in Varible x and transpose it.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jul 2018 06:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loops-to-update-allocation/m-p/475361#M122236</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-07-04T06:29:30Z</dc:date>
    </item>
  </channel>
</rss>

