<?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: Create array of price change combinations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347294#M80185</link>
    <description>&lt;P&gt;No, you misunderstand, maybe not use min/max, I meant current day - first day.&lt;/P&gt;</description>
    <pubDate>Wed, 05 Apr 2017 11:03:52 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-04-05T11:03:52Z</dc:date>
    <item>
      <title>Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347274#M80174</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to write a program that calculates an array/matrix of price changes like the one below and then calculates the maximum ( which is 9% in the case below). The example below is 7 days but I would like the flexibility of calculate any amount of days. Also, the price change can only be for consecutive days (hence half the matrix below is blank).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;Month&lt;/TD&gt;&lt;TD&gt;Week&lt;/TD&gt;&lt;TD&gt;Day&lt;/TD&gt;&lt;TD&gt;Price&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt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&lt;/TD&gt;&lt;TD&gt;107.5&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1.4%&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 05 Apr 2017 09:49:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347274#M80174</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T09:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347277#M80176</link>
      <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Post test data in the form of a datastep!!&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a normalised table, then simply lag() the value, then transpose up. &amp;nbsp;However I really don't see much point in having all the original rows there, something like:&lt;/P&gt;
&lt;PRE&gt;data inter;
  set have;
  diff=price-lag(price);
run;

proc transpose data=inter out=want;
  by year month week;
  var diff;
  id day;
run;&lt;/PRE&gt;
&lt;P&gt;This gets you the first row other than 7 and the 9.0% as its not explained anywhere where those come from or what they are.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 10:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347277#M80176</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-05T10:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347279#M80177</link>
      <description>&lt;P&gt;HI RW9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies, here is the data step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Year Month $ Week Day Price;&lt;BR /&gt;datalines;&lt;BR /&gt;2015 Jan 1 1 100&lt;BR /&gt;2015 Jan 1 2 101.5&lt;BR /&gt;2015 Jan 1 3 103&lt;BR /&gt;2015 Jan 1 4 104.5&lt;BR /&gt;2015 Jan 1 5 106&lt;BR /&gt;2015 Jan 1 6 107.5&lt;BR /&gt;2015 Jan 1 7 109&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To explain the array the first number in the first row is (101.5/100-1=1.5%), the second number in the first row is (103/100-1=3%), ..., the 6th number in the first row is (109/100-1=9%); the second number in the second row is (103/101.5-1) etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the matrix calculates every possible price change over the 7 days. There are 21 in total&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 10:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347279#M80177</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T10:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347284#M80179</link>
      <description>&lt;P&gt;Thanks. &amp;nbsp;Its not clear to me why you couldn't just take max(day)'s value and substract min(day)'s value form it to get the final output? &amp;nbsp;Anyways, this shows calculating each day, then transpose up and take the last element as total:&lt;/P&gt;
&lt;PRE&gt;data have;
infile datalines;
input Year Month $ Week Day Price;
datalines;
2015 Jan 1 1 100
2015 Jan 1 2 101.5
2015 Jan 1 3 103
2015 Jan 1 4 104.5
2015 Jan 1 5 106
2015 Jan 1 6 107.5
2015 Jan 1 7 109
;
run;
data inter;
  set have;
  retain firstprice;
  by week;
  if first.week then firstprice=price;
  else diff=price-firstprice;
run;

proc transpose data=inter out=want;
  by year month week;
  var diff;
  id day;
run;
data want;
  set want (drop=_name_);
  array vals{*} _:;
  total=vals{dim(vals)};
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Apr 2017 10:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347284#M80179</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-05T10:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347287#M80181</link>
      <description>&lt;P&gt;Hi RW9, yes that would work but&amp;nbsp;that woulnd't work if the max value occurred before the min value i.e.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Mon&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Tues&lt;/TD&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;TD&gt;Max&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Wed&lt;/TD&gt;&lt;TD&gt;110&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Thur&lt;/TD&gt;&lt;TD&gt;90&lt;/TD&gt;&lt;TD&gt;Min&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Friday&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The max increase above would be 50% (150/100), not 150/90.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 10:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347287#M80181</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T10:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347291#M80182</link>
      <description>&lt;P&gt;Hi RW9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this code for a different set of numbers and it doesn't work. See below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Year Month $ Week Day Price;&lt;BR /&gt;datalines;&lt;BR /&gt;2015 Jan 1 1 98&lt;BR /&gt;2015 Jan 1 2 87&lt;BR /&gt;2015 Jan 1 3 86&lt;BR /&gt;2015 Jan 1 4 86&lt;BR /&gt;2015 Jan 1 5 86&lt;BR /&gt;2015 Jan 1 6 87&lt;BR /&gt;2015 Jan 1 7 88&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data inter;&lt;BR /&gt;set have;&lt;BR /&gt;retain firstprice;&lt;BR /&gt;by week;&lt;BR /&gt;if first.week then firstprice=price;&lt;BR /&gt;else diff=price-firstprice;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=inter out=want;&lt;BR /&gt;by year month week;&lt;BR /&gt;var diff;&lt;BR /&gt;id day;&lt;BR /&gt;run;&lt;BR /&gt;data want;&lt;BR /&gt;set want (drop=_name_);&lt;BR /&gt;array vals{*} _:;&lt;BR /&gt;total=vals{dim(vals)};&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've changed the price data. Yuu will see the largest price increase results from 86 to 88 or 2.3%.The increase is not restricted to a daily increase. It just the biggest increase over the period.&amp;nbsp;&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>Wed, 05 Apr 2017 10:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347291#M80182</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T10:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347294#M80185</link>
      <description>&lt;P&gt;No, you misunderstand, maybe not use min/max, I meant current day - first day.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 11:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347294#M80185</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-05T11:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347297#M80187</link>
      <description>&lt;P&gt;Did you see the updated I posted with your code? It doesn't correctly calulcate the max price increase (2.3%). for 7 days, the code needs to do 21 calculations and take a mix. If there is an easier way i would definitely be open to it but the solution should give a maz of 2.3% (88/86-1) in any case.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 11:11:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347297#M80187</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T11:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347299#M80188</link>
      <description>&lt;P&gt;Don't have much time now, this is where i got, you will need ot modify for your forumal and then grab max of row total:&lt;/P&gt;
&lt;PRE&gt;data have;
infile datalines;
input Year Month $ Week Day Price;
datalines;
2015 Jan 1 1 98
2015 Jan 1 2 87
2015 Jan 1 3 86
2015 Jan 1 4 86
2015 Jan 1 5 86
2015 Jan 1 6 87
2015 Jan 1 7 88
;
run;
proc transpose data=have out=inter;
  by year month week;
  var price;
  id day;
run;
data want;
  merge have inter (drop=_name_);
  by year month week;
  array vals{*} of _:;
  do i=1 to day;
    vals{i}=.;
  end;
  do i=1 to dim(vals);
    /* Replace the vals{i}-price with your actual formula!! */
    vals{i}=ifn(vals{i} ne .,vals{i}-price,.);
  end;
  row_total=max(of vals{*});
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Apr 2017 11:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347299#M80188</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-05T11:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347304#M80191</link>
      <description>&lt;P&gt;This becomes a relatively easy problem if you skip creating DIFF. &amp;nbsp;Just transpose PRICE instead of transposing DIFF. &amp;nbsp;Then you can compare sets of 2 elements within the array and track the maximum difference.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 11:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347304#M80191</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-05T11:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347306#M80193</link>
      <description>I'm not sure I follow, would you mind elaborating</description>
      <pubDate>Wed, 05 Apr 2017 11:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347306#M80193</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T11:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347315#M80198</link>
      <description>&lt;P&gt;Hi RW9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've spent a bit of time on this and I still can't finish off the code you presented above. I'm not familiar with arrays so that is probably where the issue is. This is more complicated than I thought it would be.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 12:29:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347315#M80198</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T12:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347356#M80211</link>
      <description>&lt;P&gt;Here's some detail on transposing first, then computing differences afterwards:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc transpose data=have prefix=price_ out=want;&lt;/P&gt;
&lt;P&gt;by year month week;&lt;/P&gt;
&lt;P&gt;var price;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set want;&lt;/P&gt;
&lt;P&gt;array price_ {*};&lt;/P&gt;
&lt;P&gt;do i=1 to dim(price) - 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do j=i+1 to dim(price);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max_change = max(max_change, price_{j} / price_{i} - 1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need to compute and save all the % differences.&amp;nbsp; Just compute them one at a time, and track the maximum value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I got the formulas right here, but those are easy to change if they're wrong.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 13:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347356#M80211</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-05T13:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347361#M80214</link>
      <description>&lt;PRE&gt;
you really should take on IML code.
It is very easy for IML.




data have;
infile datalines;
input Year Month $ Week Day Price;
datalines;
2015 Jan 1 1 100
2015 Jan 1 2 101.5
2015 Jan 1 3 103
2015 Jan 1 4 104.5
2015 Jan 1 5 106
2015 Jan 1 6 107.5
2015 Jan 1 7 109
;
run;

proc iml;
use have;
read all var{price};

lag=lag(price,1:nrow(price)-1);
dif=dif(price,1:nrow(price)-1);
d=dif/lag; 

w=j(nrow(d)-1,ncol(d),.);
do i=1 to ncol(d);
 w[1:nrow(d)-i,i]=d[i+1:nrow(d),i];
end;
want=j(nrow(d)-1,ncol(d),.);
do i=1 to nrow(w);
 want[i,i:ncol(d)]=w[i,1:(ncol(d)-i+1)];
end;

create temp from want;
append from want;
close;
quit;

data want;
 merge have temp;
 max=max(of col:);
run;
proc print;run;



&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Apr 2017 14:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347361#M80214</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-05T14:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347398#M80236</link>
      <description>&lt;P&gt;I would but I don't have the SAS/IML package. This code doesn't work on my 9.3 SAS version.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 14:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347398#M80236</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T14:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347428#M80247</link>
      <description>&lt;P&gt;Hi Astounding&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Year Month $ Week Day Price;&lt;BR /&gt;datalines;&lt;BR /&gt;2015 Jan 1 1 98&lt;BR /&gt;2015 Jan 1 2 87&lt;BR /&gt;2015 Jan 1 3 86&lt;BR /&gt;2015 Jan 1 4 86&lt;BR /&gt;2015 Jan 1 5 86&lt;BR /&gt;2015 Jan 1 6 87&lt;BR /&gt;2015 Jan 1 7 88&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=have prefix=price_ out=want;&lt;BR /&gt;by year month week;&lt;BR /&gt;var price;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set want;&lt;BR /&gt;array price_ {*};&lt;BR /&gt;do i=1 to dim(price) - 1;&lt;BR /&gt;do j=i+1 to dim(price);&lt;BR /&gt;max_change = max(max_change, price_{j} / price_{i} - 1);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2123 data want;&lt;BR /&gt;2124 set want;&lt;BR /&gt;2125 array price_ {7};&lt;BR /&gt;2126 do i=1 to dim(price) - 1;&lt;BR /&gt;ERROR: The DIM, LBOUND, and HBOUND functions require an array name for&lt;BR /&gt;the first argument.&lt;BR /&gt;2127 do j=i+1 to dim(price);&lt;BR /&gt;ERROR: The DIM, LBOUND, and HBOUND functions require an array name for&lt;BR /&gt;the first argument.&lt;BR /&gt;2128 max_change = max(max_change, price_{j} / price_{i} - 1);&lt;BR /&gt;2129 end;&lt;BR /&gt;2130 end;&lt;BR /&gt;2131 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.WANT may be incomplete. When this step was&lt;BR /&gt;stopped there were 0 observations and 15 variables.&lt;BR /&gt;WARNING: Data set WORK.WANT was not replaced because this step was&lt;BR /&gt;stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 15:26:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347428#M80247</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T15:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347436#M80255</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;The op seems unable to describe the process or the result in non-speadsheet terms. This is a continuation of &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Max-price-change-within-interval-i-e-30-days-or-365-days/m-p/347126#M80136" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Max-price-change-within-interval-i-e-30-days-or-365-days/m-p/347126#M80136&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 15:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347436#M80255</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-05T15:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347442#M80260</link>
      <description>&lt;P&gt;I thought I described it quite clearly. I don't think your comment helps.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 15:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347442#M80260</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T15:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347444#M80262</link>
      <description>&lt;P&gt;My fault.&amp;nbsp; Wrong:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dim(price)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Right:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dim(price_)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DIM function requires the name of the array as an argument.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 15:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347444#M80262</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-05T15:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create array of price change combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347453#M80263</link>
      <description>&lt;P&gt;Thanks Astounding.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made the change (just replaced price with price_) but I'm still getting errors in the log. If you run the code below do you get errors?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Year Month $ Week Day Price;&lt;BR /&gt;datalines;&lt;BR /&gt;2015 Jan 1 1 98&lt;BR /&gt;2015 Jan 1 2 87&lt;BR /&gt;2015 Jan 1 3 86&lt;BR /&gt;2015 Jan 1 4 86&lt;BR /&gt;2015 Jan 1 5 86&lt;BR /&gt;2015 Jan 1 6 87&lt;BR /&gt;2015 Jan 1 7 88&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=have prefix=price_ out=want;&lt;BR /&gt;by year month week;&lt;BR /&gt;var price;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set want;&lt;BR /&gt;array price_ {*};&lt;BR /&gt;do i=1 to dim(price_) - 1;&lt;BR /&gt;do j=i+1 to dim(price_);&lt;BR /&gt;max_change = max(max_change, price_{j} / price_{i} - 1);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 16:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-array-of-price-change-combinations/m-p/347453#M80263</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-05T16:10:12Z</dc:date>
    </item>
  </channel>
</rss>

