<?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 Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125713#M34558</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This one works for me.&lt;/P&gt;&lt;P&gt;so j=0 has to be prior to the do loop and after the array statement??? AND&lt;/P&gt;&lt;P&gt;diag_codes&lt;STRONG&gt;(j)&lt;/STRONG&gt;=diag(i); has to be after j+1 strictly...&lt;/P&gt;&lt;P&gt;If i changed the order again i getr the same error!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lastly,&lt;/P&gt;&lt;P&gt;dont we need to put j=1 instead of j=0????or both would work fine???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data diag_array;&lt;BR /&gt;set daig_cohort;&lt;BR /&gt;array diag(50) dx1-dx50;&lt;BR /&gt;array diag_codes(10) diag_codes1 - diag_codes10; &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;j=0&lt;/STRONG&gt;&lt;BR /&gt;do i=1 to 35;&lt;BR /&gt;&amp;nbsp; if diag(i) in ('123','245','687','890','432','472', '42760', '42761', '4278', '42781', '42789', '4279') then do; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diag_flag=1;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;j+1;&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diag_codes&lt;STRONG&gt;(j)&lt;/STRONG&gt;=diag(i);&lt;BR /&gt;&amp;nbsp; drop i&amp;nbsp; j /*diag_code*/;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 30 Apr 2013 18:47:32 GMT</pubDate>
    <dc:creator>robertrao</dc:creator>
    <dc:date>2013-04-30T18:47:32Z</dc:date>
    <item>
      <title>Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125709#M34554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following code.&lt;/P&gt;&lt;P&gt;There are a max of 50 codes in the array diag&lt;/P&gt;&lt;P&gt;some can have only 5 codes etc....&lt;/P&gt;&lt;P&gt;i want to put the codes which satisfy the if condition in&amp;nbsp; seperate columns.&lt;/P&gt;&lt;P&gt;Assuming the max of 10 codes a single observation can satisfy in the if condition ....I am using the following code and get an error&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR: Array subscript out of range at line 454 column 13.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please correct me&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data diag_array;&lt;BR /&gt;set daig_cohort;&lt;BR /&gt;array diag(50) dx1-dx50;&lt;BR /&gt;array diag_codes(10) diag_codes1 - diag_codes10; &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;do i=1 to 35;&lt;BR /&gt;&amp;nbsp; if diag(i) in ('123','245','687','890','432','472', '42760', '42761', '4278', '42781', '42789', '4279') then do; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diag_flag=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diag_codes(i)=diag(i);&lt;BR /&gt;&amp;nbsp; drop i /*diag_code*/;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 17:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125709#M34554</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-04-30T17:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125710#M34555</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;if dx1-dx50 are character variables, you need to change&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array diag_codes(10) diag_codes1 - diag_codes10;&lt;/P&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;array diag_codes(10) &lt;SPAN style="color: #ff0000;"&gt;$&lt;/SPAN&gt; diag_codes1 - diag_codes10;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 18:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125710#M34555</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2013-04-30T18:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125711#M34556</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also, since i goes up to 50, you can't use it to reference an array that has only 10 elements.&amp;nbsp; That's the source of the error message about array subscript out of range.&amp;nbsp; Instead, add before the IF/THEN statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;j=0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then inside the IF/THEN group:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;diag_flag=1;&lt;/P&gt;&lt;P&gt;j + 1;&lt;/P&gt;&lt;P&gt;diag_codes{j} = diag{i};&lt;/P&gt;&lt;P&gt;drop i j;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 18:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125711#M34556</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-04-30T18:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125712#M34557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thanks for the reply.&lt;/P&gt;&lt;P&gt;I still get that error even after putting the dollar sign&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 18:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125712#M34557</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-04-30T18:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125713#M34558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This one works for me.&lt;/P&gt;&lt;P&gt;so j=0 has to be prior to the do loop and after the array statement??? AND&lt;/P&gt;&lt;P&gt;diag_codes&lt;STRONG&gt;(j)&lt;/STRONG&gt;=diag(i); has to be after j+1 strictly...&lt;/P&gt;&lt;P&gt;If i changed the order again i getr the same error!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lastly,&lt;/P&gt;&lt;P&gt;dont we need to put j=1 instead of j=0????or both would work fine???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data diag_array;&lt;BR /&gt;set daig_cohort;&lt;BR /&gt;array diag(50) dx1-dx50;&lt;BR /&gt;array diag_codes(10) diag_codes1 - diag_codes10; &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;j=0&lt;/STRONG&gt;&lt;BR /&gt;do i=1 to 35;&lt;BR /&gt;&amp;nbsp; if diag(i) in ('123','245','687','890','432','472', '42760', '42761', '4278', '42781', '42789', '4279') then do; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diag_flag=1;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;j+1;&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diag_codes&lt;STRONG&gt;(j)&lt;/STRONG&gt;=diag(i);&lt;BR /&gt;&amp;nbsp; drop i&amp;nbsp; j /*diag_code*/;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 18:47:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125713#M34558</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-04-30T18:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125714#M34559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Whatever combination of statements you use, the important part is this.&amp;nbsp; When SAS executes this statement, j must be between 1 and 10:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;diag_codes{j} = diag{i};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If j is 0 at that point, you will get the same error message.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 18:54:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125714#M34559</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-04-30T18:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125715#M34560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you have an array sized 10, but 12 elements in your IN() component, so you'll run out of spaces if one person has all 12 diagnosis.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 19:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125715#M34560</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-04-30T19:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125716#M34561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Those 12 in the in operator are a subset of 50 codes(max number) from the diag array.&lt;/P&gt;&lt;P&gt;so i am checking to look for any of these 12 codes&amp;nbsp; in the 50(some might have only 5 codes but the other 45 are missing..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope you got what i am trying to explain&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 19:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125716#M34561</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-04-30T19:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125717#M34562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another way to think about the problem is instead of copying the DX codes you could set separate flag variables for each of the codes.&lt;/P&gt;&lt;P&gt;This code will create 10 flag variables. FLAG1 = '1' when diagnosis code '123' is present in any of the 50 DX variables.&amp;nbsp; FLAG2 is for diagnosis code '245'. etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;set diag_cohort ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;array dx dx1-dx50 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;array search (10) $5 _temporary_ &lt;SPAN style="background-color: #ffffff;"&gt;('123','245','687','890','432','472', '42760', '42761', '4278', '42781', '42789', '4279')&lt;/SPAN&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;array flag (10) $1 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;do i=1 to dim(search);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; if which(search(i),of dx(*) ) then flag(i)='1';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else flag(i)='0';&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 22:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Arrays/m-p/125717#M34562</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-04-30T22:04:16Z</dc:date>
    </item>
  </channel>
</rss>

