<?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: Using a dynamic number in arrays in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55701#M15529</link>
    <description>Hi Patrick, and thanks for the reply.&lt;BR /&gt;
&lt;BR /&gt;
I can't get the sql to work, it says that the "cats" argument is unknown or used out of order. &lt;BR /&gt;
&lt;BR /&gt;
Im not very experienced with sql, so i have no idea where to start troubleshooting.&lt;BR /&gt;
&lt;BR /&gt;
-t</description>
    <pubDate>Tue, 28 Dec 2010 12:24:05 GMT</pubDate>
    <dc:creator>TMorville</dc:creator>
    <dc:date>2010-12-28T12:24:05Z</dc:date>
    <item>
      <title>Using a dynamic number in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55699#M15527</link>
      <description>Hi everyone and merry xmas!&lt;BR /&gt;
&lt;BR /&gt;
I have a quick question, that i don't quite know how to google.&lt;BR /&gt;
&lt;BR /&gt;
I have a datastep with arrays in it:&lt;BR /&gt;
&lt;BR /&gt;
data rotate;&lt;BR /&gt;
set retain_test;&lt;BR /&gt;
by bp_2;&lt;BR /&gt;
retain numabb17-numabb43;&lt;BR /&gt;
array Anumabb(17:43) numabb17-numabb43;&lt;BR /&gt;
if first.bp_2 then do;&lt;BR /&gt;
 do i = 17 to 43;&lt;BR /&gt;
	Anumabb&lt;I&gt; = .;&lt;BR /&gt;
 end;&lt;BR /&gt;
end;&lt;BR /&gt;
Anumabb(week) = numabb;&lt;BR /&gt;
if last.bp_2 then output;&lt;BR /&gt;
drop week i;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
This is just part of the code. What i would like to do, is to have two variables for the weeknumbers. So instead of writeing 17 and 43, i predefine them above, and then i can change them as i wish to.&lt;BR /&gt;
&lt;BR /&gt;
Im thinking something like this:&lt;BR /&gt;
&lt;BR /&gt;
startweek = 17&lt;BR /&gt;
endweek = 43 &lt;BR /&gt;
&lt;BR /&gt;
data rotate;&lt;BR /&gt;
set retain_test;&lt;BR /&gt;
by bp_2;&lt;BR /&gt;
retain numabb(startweek)-numabb(endweek);&lt;BR /&gt;
array Anumabb((startweek):(endweek) numabb(startweek)-numabb(endweek);&lt;BR /&gt;
if first.bp_2 then do;&lt;BR /&gt;
 do i = (startweek) to (endweek);&lt;BR /&gt;
	Anumabb&lt;I&gt; = .;&lt;BR /&gt;
 end;&lt;BR /&gt;
end;&lt;BR /&gt;
Anumabb(week) = numabb;&lt;BR /&gt;
if last.bp_2 then output;&lt;BR /&gt;
drop week i;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
Any ideas?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;BR /&gt;
Toby

Message was edited by: TMorville&lt;/I&gt;&lt;/I&gt;</description>
      <pubDate>Tue, 28 Dec 2010 10:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55699#M15527</guid>
      <dc:creator>TMorville</dc:creator>
      <dc:date>2010-12-28T10:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using a dynamic number in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55700#M15528</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
Below code probabely does what you're after:&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select cats(max(week)), cats(min(week)) into :maxweek, :minweek&lt;BR /&gt;
  from retain_test&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/* alternative to SQL above - but less dynamic:&lt;BR /&gt;
%let minweek=17;&lt;BR /&gt;
%let maxweek=43;&lt;BR /&gt;
*/ &lt;BR /&gt;
&lt;BR /&gt;
data rotate;&lt;BR /&gt;
  set retain_test;&lt;BR /&gt;
  by bp_2;&lt;BR /&gt;
  array Anumabb(*) 8 numabb&amp;amp;minweek. - numabb&amp;amp;maxweek.;&lt;BR /&gt;
  retain numabb&amp;amp;minweek. - numabb&amp;amp;maxweek.;&lt;BR /&gt;
&lt;BR /&gt;
  if first.bp_2 then call missing(of Anumabb(*));&lt;BR /&gt;
&lt;BR /&gt;
  Anumabb(week) = numabb;&lt;BR /&gt;
&lt;BR /&gt;
  if last.bp_2 then output;&lt;BR /&gt;
&lt;BR /&gt;
  drop week;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I assume in your real code there are more transformations. &lt;BR /&gt;
If not then Proc Transpose might be another way to go.&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=retain_test out=rotate prefix=numabb;&lt;BR /&gt;
  by bp_2;&lt;BR /&gt;
  id week;&lt;BR /&gt;
  var numabb;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Patrick

added missing SELECT to SQL&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Patrick</description>
      <pubDate>Tue, 28 Dec 2010 11:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55700#M15528</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-12-28T11:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using a dynamic number in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55701#M15529</link>
      <description>Hi Patrick, and thanks for the reply.&lt;BR /&gt;
&lt;BR /&gt;
I can't get the sql to work, it says that the "cats" argument is unknown or used out of order. &lt;BR /&gt;
&lt;BR /&gt;
Im not very experienced with sql, so i have no idea where to start troubleshooting.&lt;BR /&gt;
&lt;BR /&gt;
-t</description>
      <pubDate>Tue, 28 Dec 2010 12:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55701#M15529</guid>
      <dc:creator>TMorville</dc:creator>
      <dc:date>2010-12-28T12:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using a dynamic number in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55702#M15530</link>
      <description>The CATS (and other CAT-related functions were added with SAS 9), however I also notice that the PROC SQL code is missing a "SELECT".&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
proc sql site:sas.com</description>
      <pubDate>Tue, 28 Dec 2010 12:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55702#M15530</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-12-28T12:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using a dynamic number in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55703#M15531</link>
      <description>Hi.&lt;BR /&gt;
You can remove cats(), directly use max(week).&lt;BR /&gt;
I think Patrick used function cats() is just to want to delete the surplus blanks.&lt;BR /&gt;
Actually ,the macro variable will automatically remove the heading and trailing blanks.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Sorry. I am wrong. Actually Proc Sql will keep heading and trailing blanks for the single macro variable.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Wed, 29 Dec 2010 01:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55703#M15531</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-12-29T01:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using a dynamic number in arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55704#M15532</link>
      <description>Toby,&lt;BR /&gt;
&lt;BR /&gt;
I'm surprised that anyone could even attempt to answer your question without knowing what you incoming data look like and how you want the resulting data to appear.&lt;BR /&gt;
&lt;BR /&gt;
Some example data, in the form of a datastep, would definitely help.&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Fri, 31 Dec 2010 02:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-a-dynamic-number-in-arrays/m-p/55704#M15532</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-12-31T02:16:35Z</dc:date>
    </item>
  </channel>
</rss>

