<?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: Use last. first. with an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439102#M109530</link>
    <description>&lt;P&gt;Your current example only has one variable, DOSE.&amp;nbsp; Can you post an example with an array of two or more variables?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is you want to do with this array?&lt;/P&gt;
&lt;P&gt;Are you trying to sum each column (variable) in the array?&lt;/P&gt;
&lt;P&gt;If so then you will need to a matching array of result variables rather than just the single N_DAYS variable.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Feb 2018 22:06:17 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-02-21T22:06:17Z</dc:date>
    <item>
      <title>Use last. first. with an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439095#M109524</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use first. and last. with an array statement. It should work like this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;&lt;BR /&gt;data have;
informat date mmddyy8.;
format date date9.;
 input dose  id $ supply date ;
 datalines;
5 1234 30 01012015
10 1234 30 02012015
10 1234 30 03012015
5 1234 30 04012015
2 1234 30 05012015
5 4321 30 07012016
2 9876 30 05012016
2 9876 30 06012016
10 9876 30 07012016
 ;
run;

proc sort data=have;
  by id date;
run;

data want;
set have;
by id dose notsorted;
retain n_days;
array my_array[*] dose id; &lt;BR /&gt;do i=1 to dim(my_array);
if first.myarray(i)then n_days=0;
end;
n_days+supply;

if last.dose then output;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Since the real array contains more than 200 variables it is not possible to do this manually.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2018 21:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439095#M109524</guid>
      <dc:creator>gklsc</dc:creator>
      <dc:date>2018-02-21T21:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Use last. first. with an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439099#M109527</link>
      <description>&lt;P&gt;Well, two things to consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, this problem has nothing to do with arrays.&amp;nbsp; Zero.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, this problem requires understanding what your BY variables look like.&amp;nbsp; You could just as easily code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if first.dose then n_days=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That would set n_days properly.&amp;nbsp; Whenever you hit the first observation for an ID, first.dose is true.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2018 21:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439099#M109527</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-21T21:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Use last. first. with an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439100#M109528</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand why you want to use First. on all the 200 columns you have.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you trying to calculate the variable values by dose,Id like:&lt;/P&gt;&lt;P&gt;Days1+Supply1;&lt;/P&gt;&lt;P&gt;Days2+Supply2;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.So on until all 200 variables&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2018 22:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439100#M109528</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-02-21T22:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Use last. first. with an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439102#M109530</link>
      <description>&lt;P&gt;Your current example only has one variable, DOSE.&amp;nbsp; Can you post an example with an array of two or more variables?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is you want to do with this array?&lt;/P&gt;
&lt;P&gt;Are you trying to sum each column (variable) in the array?&lt;/P&gt;
&lt;P&gt;If so then you will need to a matching array of result variables rather than just the single N_DAYS variable.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2018 22:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439102#M109530</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-21T22:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Use last. first. with an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439103#M109531</link>
      <description>&lt;P&gt;What you are trying to do&amp;nbsp;is not obvious from your code. But I think you should revise the workings of FIRST, LAST and BY variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;BY Var1 Var2 Var3;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;first.Var3 is always 1 if either first.Var1 or first.Var2 is 1. So it might be enough for your purpose to monitor first.Var3.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2018 22:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439103#M109531</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-02-21T22:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Use last. first. with an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439107#M109534</link>
      <description>&lt;P&gt;Are you trying to do this type of calculation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input dose  id $ supply supply2 supply3 ;
 datalines;
5 1234 30 40 50
10 1234 30 40 50
10 1234 30 40 50
5 1234 30 40 50
2 1234 30 40 50
5 4321 30 40 50
2 9876 30 40 50
2 9876 30 40 50
10 9876 30 40 50
 ;
run;

proc sort data=have;
  by id dose;
run;

data want(DROP=Supply Supply2 Supply3);
set have;
by id dose;
IF first.id and first.dose then Do;
	Supply_1=supply;
	Supply_2=supply2;
	supply_3=supply3;
	end;
Else do;
Supply_1+Supply;
Supply_2+Supply2;
Supply_3+Supply3;
end;
if last.dose then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Feb 2018 22:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-last-first-with-an-array/m-p/439107#M109534</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-02-21T22:23:42Z</dc:date>
    </item>
  </channel>
</rss>

