<?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: Arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652053#M195717</link>
    <description>Do you need the intermediate steps or just the final result?</description>
    <pubDate>Sun, 31 May 2020 03:00:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-05-31T03:00:16Z</dc:date>
    <item>
      <title>Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652050#M195715</link>
      <description>I want to write a code to multiply vector 1 starting at the beginning by vector 2, only vector 2 will move down one at every iteration while vector one will always begin at the beginning. The example given is on a much smaller scale, use lags would become much too large (400 periods / 200 variables ).</description>
      <pubDate>Sun, 31 May 2020 02:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652050#M195715</guid>
      <dc:creator>smurray</dc:creator>
      <dc:date>2020-05-31T02:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652053#M195717</link>
      <description>Do you need the intermediate steps or just the final result?</description>
      <pubDate>Sun, 31 May 2020 03:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652053#M195717</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-31T03:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652056#M195718</link>
      <description>Intermediate steps too please</description>
      <pubDate>Sun, 31 May 2020 03:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652056#M195718</guid>
      <dc:creator>smurray</dc:creator>
      <dc:date>2020-05-31T03:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652065#M195720</link>
      <description>&lt;P&gt;Is below doing what you're after?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do x=1 to 5;
    y=x+2;
    output;
  end;
  stop;
run;

/* get number of rows used as number of required array elements */
data _null_;
  call symputx('nobs',nobs);
  stop;
  set have nobs=nobs;
run;
%put &amp;amp;=nobs;

data want(drop=_: vx_: vy_:);
  if 0 then set have(keep=x y);
  length result 8;
  
  array vx_ {&amp;amp;nobs} 8;
  array vy_ {&amp;amp;nobs} 8;
  array step_ {&amp;amp;nobs} 8;

  do while(not last);
    set have end=last;
    _i+1;
    vx_[_i]=x;
    vy_[_i]=y;
  end;

  do _i=1 to &amp;amp;nobs;
    _sX=1;
    _startY+1;
    call missing(result, of step_{*});
    do _sy=_startY to dim(vy_);
      step_[_sx]=vx_[_sx]*vy_[_sy];
      _sX+1;
    end;
    x=vx_{_i};
    y=vy_{_i};
    result=sum(of step_[*]);
    output;
  end;
  stop;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1590898965060.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40187i1068BDCAB8270BD1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1590898965060.png" alt="Patrick_0-1590898965060.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 04:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652065#M195720</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-05-31T04:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652131#M195752</link>
      <description>It is- thank you! Is it possible to run this by group (if first start calculation over) - would that be a change to the do while section?</description>
      <pubDate>Mon, 01 Jun 2020 01:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652131#M195752</guid>
      <dc:creator>smurray</dc:creator>
      <dc:date>2020-06-01T01:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652404#M195855</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/221548"&gt;@smurray&lt;/a&gt;&amp;nbsp;Below one way how to go for processing by group.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do group=1 to 3;
    do x=1 to 5;
/*      y=x+1+group;*/
      y=x+2;
      output;
      if group=2 and x=3 then leave;
    end;
  end;
  stop;
run;

/* get max number of rows in a group to define required array elements */
proc sql noprint;
  select max(cnt) into :max_grp trimmed
  from
    (
      select count(*) as cnt 
      from have
      group by group
    )
  ;
quit;
%put &amp;amp;=max_grp;

data want(keep=group x y result step_:);
  if 0 then set have;
  length result 8;
  
  array vx_ {&amp;amp;max_grp} 8;
  array vy_ {&amp;amp;max_grp} 8;
  array step_ {&amp;amp;max_grp} 8;

  do while(not last);
    set have end=last;
    by group;
    _stop+1;
    vx_[_stop]=x;
    vy_[_stop]=y;

    if last.group then
      do;
        do _i=1 to _stop;
          _sX=1;
          _startY+1;
          call missing(result, of step_[*]);
          do _sy=_startY to dim(vy_);
            step_[_sx]=vx_[_sx]*vy_[_sy];
            _sX+1;
          end;
          x=vx_{_i};
          y=vy_{_i};
          result=sum(of step_[*]);
          output;
        end;
        call missing(of _all_);
      end;
  end;
  stop;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1591059952869.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40242iE42C16970D66BA05/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1591059952869.png" alt="Patrick_0-1591059952869.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 01:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/652404#M195855</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-02T01:07:08Z</dc:date>
    </item>
  </channel>
</rss>

