<?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 Processing multiple variables in array/ do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-variables-in-array-do-loop/m-p/331323#M74442</link>
    <description>&lt;P&gt;Have:&lt;/P&gt;&lt;P&gt;- 4 variables for CD4 count (CD4_1, CD4_2, CD4_3 CD4_4)&lt;/P&gt;&lt;P&gt;- 4 variables for the date when the CD4 count was measured (CD4_date1, CD4_date2, CD4_date3, CD4_date4)&lt;/P&gt;&lt;P&gt;- 1 variable specifying the start date of the study&amp;nbsp;period (start_sp)&lt;/P&gt;&lt;P&gt;- 1 variable specifying the end date of the study&amp;nbsp;period (end_sp)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want to create 3 new dichotomous variables:&lt;/P&gt;&lt;P&gt;- CD4_1000, indicates if the individual had a CD4 count less than 1000, with the date of the test falling&amp;nbsp;between the start and end of the study period (start_sp and end_sp)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- CD4_500, indicates if the individual had a CD4 count less than 500, with the date of the test falling&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;between the start and end of the study period (start_sp and end_sp)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- CD4_350, indicates if the individual had a CD4 count less than 350, with the date of the test falling&amp;nbsp;between the start and end of the study period (start_sp and end_sp)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My question is how to create these 3 variables without a paragraph of if then's. This creates the 3 variables, but only incorporates the counts of the tests, not the dates:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;array CD4 [*] CD4Count;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;CD4_350 = 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;CD4_500 = 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;CD4_1000 = 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;do i = 1 to dim(CD4);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if CD4[i] &amp;lt; 350 then CD4_350 = 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if CD4[i] &amp;lt; 500 then CD4_500 = 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if CD4[i] &amp;lt; 1000 CD4_1000 = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I modify this to include the requirement that the date of the test had to occur within the study period?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Feb 2017 20:54:50 GMT</pubDate>
    <dc:creator>abmitch95</dc:creator>
    <dc:date>2017-02-09T20:54:50Z</dc:date>
    <item>
      <title>Processing multiple variables in array/ do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-variables-in-array-do-loop/m-p/331323#M74442</link>
      <description>&lt;P&gt;Have:&lt;/P&gt;&lt;P&gt;- 4 variables for CD4 count (CD4_1, CD4_2, CD4_3 CD4_4)&lt;/P&gt;&lt;P&gt;- 4 variables for the date when the CD4 count was measured (CD4_date1, CD4_date2, CD4_date3, CD4_date4)&lt;/P&gt;&lt;P&gt;- 1 variable specifying the start date of the study&amp;nbsp;period (start_sp)&lt;/P&gt;&lt;P&gt;- 1 variable specifying the end date of the study&amp;nbsp;period (end_sp)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want to create 3 new dichotomous variables:&lt;/P&gt;&lt;P&gt;- CD4_1000, indicates if the individual had a CD4 count less than 1000, with the date of the test falling&amp;nbsp;between the start and end of the study period (start_sp and end_sp)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- CD4_500, indicates if the individual had a CD4 count less than 500, with the date of the test falling&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;between the start and end of the study period (start_sp and end_sp)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- CD4_350, indicates if the individual had a CD4 count less than 350, with the date of the test falling&amp;nbsp;between the start and end of the study period (start_sp and end_sp)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My question is how to create these 3 variables without a paragraph of if then's. This creates the 3 variables, but only incorporates the counts of the tests, not the dates:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;array CD4 [*] CD4Count;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;CD4_350 = 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;CD4_500 = 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;CD4_1000 = 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;do i = 1 to dim(CD4);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if CD4[i] &amp;lt; 350 then CD4_350 = 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if CD4[i] &amp;lt; 500 then CD4_500 = 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if CD4[i] &amp;lt; 1000 CD4_1000 = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I modify this to include the requirement that the date of the test had to occur within the study period?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 20:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-variables-in-array-do-loop/m-p/331323#M74442</guid>
      <dc:creator>abmitch95</dc:creator>
      <dc:date>2017-02-09T20:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Processing multiple variables in array/ do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-variables-in-array-do-loop/m-p/331345#M74448</link>
      <description>&lt;P&gt;Some example input data and output for that is desireable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code as shown is only going to process 1 variable comparison, that of CD4Count.&lt;/P&gt;
&lt;P&gt;You may have meant&lt;/P&gt;
&lt;P&gt;array cd cd4_1 - cd4_4 ; so that the base values are those four.&lt;/P&gt;
&lt;P&gt;a second array would be needed to have the matching date&lt;/P&gt;
&lt;P&gt;array d cd4_date1 - cd4_date4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your if statements would look something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if cd[i] &amp;lt; (value) and (startdate le d[i] le enddate) then do ...&lt;/P&gt;
&lt;P&gt;if the date isn't suppose to match the start/end to be "within period" then use lt or &amp;lt; insted of le.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HOWEVER you have a logic problem in that if the cd4_4 &amp;lt; 350 (or missing as missing is less than any value in SAS )&amp;nbsp;all of the resulting cd4_350, cd4_500 and cd4_1000 will all be true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure what you want for the cd4_350 for instance as it may well change with each cd4 count variable.&lt;/P&gt;
&lt;P&gt;Suppose Cd4_1=200, cd4_2=600, cd4_3=900, and cd4_4=1200. Then the first will set cd_350, cd4_500 and cd4_1000 all to 1.&lt;/P&gt;
&lt;P&gt;there won't be any change in the cd4_350/500/1000 variables. This may be what you want if the interpretation is "at sometime within the study period at least one of the Cd4 counts was less than XXXX"&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 21:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-variables-in-array-do-loop/m-p/331345#M74448</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-09T21:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Processing multiple variables in array/ do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-variables-in-array-do-loop/m-p/331395#M74468</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do I = 1 to dim(CD4);
  CD4_350 =(  . &amp;lt; CD4[I] &amp;lt;=  350) * ( START_SP&amp;lt;CD4_DATE[I]&amp;lt;END_SP) * CD4_DATE[I];
  CD4_500 =(350 &amp;lt; CD4[I] &amp;lt;=  500) * ( START_SP&amp;lt;CD4_DATE[I]&amp;lt;END_SP) * CD4_DATE[I];
  CD4_1000=(500 &amp;lt; CD4[I] &amp;lt;= 1000) * ( START_SP&amp;lt;CD4_DATE[I]&amp;lt;END_SP) * CD4_DATE[I];
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will store the test date provided the value is within the range and the date is with the date boundaries too.&lt;/P&gt;
&lt;P&gt;Otherwise it will store zero.&lt;/P&gt;
&lt;P&gt;The elements in the parentheses are tests and resolve to either 0 or 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 04:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Processing-multiple-variables-in-array-do-loop/m-p/331395#M74468</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-02-10T04:05:18Z</dc:date>
    </item>
  </channel>
</rss>

