<?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 Need help with setting an array for an algorithm in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-setting-an-array-for-an-algorithm/m-p/835937#M330517</link>
    <description>&lt;P&gt;Hello Community.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this algorithm given to me and was asked to generate new variable . I'm not finding right way to do it. Could you please help me with it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data chk;&lt;BR /&gt;input subject$ week$ numdisp pilre dose_taken;&lt;BR /&gt;datalines;&lt;BR /&gt;1 week1 10 . .&lt;BR /&gt;1 week2 10 3 100&lt;BR /&gt;1 week3 10 1 200&lt;BR /&gt;2 week2 20 . .&lt;BR /&gt;2 week3 10 3 300&lt;BR /&gt;3 week1 10 . .&lt;BR /&gt;3 week2 30 0 100&lt;BR /&gt;3 week3 20 2 200&lt;BR /&gt;3 week4 30 5 300&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The weeks in this gets added every week. From this dataset i want to create a new variable called CDOSE for each subject(populated at the last visit). and it should be derived as follows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[&lt;/P&gt;&lt;P&gt;( NUMDISP(WEEK1) - PILRE(WEEK2) +&lt;/P&gt;&lt;P&gt;&amp;nbsp; NUMDISP(WEEK2) - PILRE(WEEK3)&lt;/P&gt;&lt;P&gt;&amp;nbsp; NUMDISP(WEEK3) - PILRE(WEEK4)&amp;nbsp; &amp;nbsp;) *100&lt;/P&gt;&lt;P&gt;+ dose_taken of the last week &lt;STRONG&gt;(example subject-3 's last week is 4 so we will take 300)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: some subjects do not have all weeks . ex: subject-2 doesnt have week 1 so for this algorithm would be like this:&lt;/P&gt;&lt;P&gt;[&lt;/P&gt;&lt;P&gt;( NUMDISP(WEEK2) - PILRE(WEEK3) &amp;nbsp;) *100&lt;/P&gt;&lt;P&gt;+ dose_taken of the last week&amp;nbsp;&lt;/P&gt;&lt;P&gt;]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Sep 2022 20:14:06 GMT</pubDate>
    <dc:creator>abhisas1</dc:creator>
    <dc:date>2022-09-29T20:14:06Z</dc:date>
    <item>
      <title>Need help with setting an array for an algorithm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-setting-an-array-for-an-algorithm/m-p/835937#M330517</link>
      <description>&lt;P&gt;Hello Community.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this algorithm given to me and was asked to generate new variable . I'm not finding right way to do it. Could you please help me with it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data chk;&lt;BR /&gt;input subject$ week$ numdisp pilre dose_taken;&lt;BR /&gt;datalines;&lt;BR /&gt;1 week1 10 . .&lt;BR /&gt;1 week2 10 3 100&lt;BR /&gt;1 week3 10 1 200&lt;BR /&gt;2 week2 20 . .&lt;BR /&gt;2 week3 10 3 300&lt;BR /&gt;3 week1 10 . .&lt;BR /&gt;3 week2 30 0 100&lt;BR /&gt;3 week3 20 2 200&lt;BR /&gt;3 week4 30 5 300&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The weeks in this gets added every week. From this dataset i want to create a new variable called CDOSE for each subject(populated at the last visit). and it should be derived as follows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[&lt;/P&gt;&lt;P&gt;( NUMDISP(WEEK1) - PILRE(WEEK2) +&lt;/P&gt;&lt;P&gt;&amp;nbsp; NUMDISP(WEEK2) - PILRE(WEEK3)&lt;/P&gt;&lt;P&gt;&amp;nbsp; NUMDISP(WEEK3) - PILRE(WEEK4)&amp;nbsp; &amp;nbsp;) *100&lt;/P&gt;&lt;P&gt;+ dose_taken of the last week &lt;STRONG&gt;(example subject-3 's last week is 4 so we will take 300)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: some subjects do not have all weeks . ex: subject-2 doesnt have week 1 so for this algorithm would be like this:&lt;/P&gt;&lt;P&gt;[&lt;/P&gt;&lt;P&gt;( NUMDISP(WEEK2) - PILRE(WEEK3) &amp;nbsp;) *100&lt;/P&gt;&lt;P&gt;+ dose_taken of the last week&amp;nbsp;&lt;/P&gt;&lt;P&gt;]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 20:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-setting-an-array-for-an-algorithm/m-p/835937#M330517</guid>
      <dc:creator>abhisas1</dc:creator>
      <dc:date>2022-09-29T20:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with setting an array for an algorithm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-setting-an-array-for-an-algorithm/m-p/835994#M330542</link>
      <description>&lt;P&gt;Here is a code to create the arrays you need.&lt;/P&gt;
&lt;P&gt;I leave it to you to add the computation.&lt;/P&gt;
&lt;P&gt;Data is assumed to be sorted by subject;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data computed;
 set have;
      by subject;
          retain ndisp1-ndisp4 pil1-pil4;
          array nd {4} ndisp1-ndisp4;
          array pl {4} pil1-pil4;
          if first.subject then do i=1 to 4;  /* clear arrays */
             nd(i)=.;  pl(i)=.;
         end;

         /* do for every observation per subject = save data in the arrays */
          i = input(substr(week,1,1),1.);    /* week nomber 1 to 4 */
          nd(i) = numdisp;
          pl(i)  = pilre;

          if last.subject then do;
            /*  compute the CDOSE by formula */&lt;BR /&gt;            ......
            output;
         end;&lt;BR /&gt;         keep subject cdose;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;You may need to merge HAVE and COMPUTED tables by SUBJECT to have CDOSE variable on each observation.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 05:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-setting-an-array-for-an-algorithm/m-p/835994#M330542</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2022-09-30T05:03:54Z</dc:date>
    </item>
  </channel>
</rss>

