<?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: array and loops? recoding into different variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104019#M21727</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here are a couple of approaches when your groups have unequal width.&amp;nbsp; First an assignment statement - this will be faster than IF-THEN/ELSE processing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; i = 1 * (0 &amp;lt;=ratelist{r} &amp;lt;25)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; +2 * (25&amp;lt;=ratelist{r} &amp;lt;40)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; +3 * (40&amp;lt;=ratelist{r} &amp;lt;60)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; +4 * (60&amp;lt;=ratelist{r} &amp;lt;90)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; +5 * (90&amp;lt;=ratelist{r});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could also create an informat that maps the RATELIST{r} to the index value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;BR /&gt;invalue raterange&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 0 -&amp;lt;25=1&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 25-&amp;lt;40=2&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 40-&amp;lt;60=3&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 60-&amp;lt;90=4&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 90-high=5;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The assignment statement then becomes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = input(ratelist{r},raterange.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the number of ranges becomes much more than 5 I would recommend the format approach.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Feb 2013 23:10:00 GMT</pubDate>
    <dc:creator>ArtC</dc:creator>
    <dc:date>2013-02-11T23:10:00Z</dc:date>
    <item>
      <title>array and loops? recoding into different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104014#M21722</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 a number of variables i'd like to recode into different variables by range, my data looks like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;id Rate1 Rate2 Rate3 Rate4&lt;/P&gt;&lt;P&gt;1 0 10 23 54&lt;/P&gt;&lt;P&gt;2 18 39 23 84&lt;/P&gt;&lt;P&gt;3 4 87 92 8&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to create new variables that group them into category indicators for each Rate&lt;/P&gt;&lt;P&gt;0-25, 25-50, 50-75, 75-max&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like the data to come out:&lt;/P&gt;&lt;P&gt;id Rate1 Rate2 Rate3 Rate4 R1_0_25 R1_25_50 R1_50_75 R1_75_M R2_0_25 R2_25_50 R2_50_75 R2_75_M R3_0_25 R3_25_50 R3_50_75 R3_75_M&amp;nbsp; R4_0_25 R4_25_50 R4_50_75 R4_75_M&lt;/P&gt;&lt;P&gt;1 0 10 23 54 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0&lt;/P&gt;&lt;P&gt;2 18 39 23 84 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1&lt;/P&gt;&lt;P&gt;3 4 87 92 8 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I started with array's but i didnt think through it very clearly yet so that didnt work, any help is very much appreciated!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ARRAY RATELIST {*} RATE1 RATE2 RATE3 RATE4 ;&lt;/P&gt;&lt;P&gt;ARRAY NEWCAT {*} R1_75_M R2_0_25 R2_25_50 R2_50_75 R2_75_M R3_0_25 R3_25_50 R3_50_75 R3_75_M&amp;nbsp; R4_0_25 R4_25_50 R4_50_75 R4_75_M ;&lt;/P&gt;&lt;P&gt;Do i=1 to dim(NEWCAT) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if 0 LE RATELIST{i} LE 25 then NEWCAT{i}= 1; else NEWCAT{i}=0 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if 25 LE RATELIST{i} LE 50 then NEWCAT{i}= 1; else NEWCAT{i}=0 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if 50 LE RATELIST{i} LE 75 then NEWCAT{i}= 1; else NEWCAT{i}=0 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if RATELIST{i} GE 75 then NEWCAT{i}= 1; else NEWCAT{i}=0 ;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;end; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2013 21:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104014#M21722</guid>
      <dc:creator>Danglytics</dc:creator>
      <dc:date>2013-02-08T21:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: array and loops? recoding into different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104015#M21723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have a problem in that you have the values of 25, 50, and 75 assigned to two categories when equal. Which category do you want when value is exactly equal to 25?&lt;/P&gt;&lt;P&gt;How will you use these recoded values? It may be that you don't need to create a new variable but a custom format.&lt;/P&gt;&lt;P&gt;For example if I wanted to run proc freq on the rates and know how many and percent were within the range then I could do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc format;&lt;/P&gt;&lt;P&gt;value quartile&lt;/P&gt;&lt;P&gt;0 - &amp;lt; 25 = '0 to &amp;lt; 25'&lt;/P&gt;&lt;P&gt;25 -&amp;lt;50 = '25 to &amp;lt;50'&lt;/P&gt;&lt;P&gt;50 -&amp;lt;75 = '50 to &amp;lt;75'&lt;/P&gt;&lt;P&gt;75 - high='75+'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data=yourdatasetname;&lt;/P&gt;&lt;P&gt;tables rate1 rate2 rate3 rate4;&lt;/P&gt;&lt;P&gt;format rate1 rate2 rate3 rate4 quartile.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Most of the analysis procedures will use the formatted value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or to recode one:&lt;/P&gt;&lt;P&gt;R2_0_25 = (0 le Rate2 le 25); /* though I think you may want (0 le Rate2 lt 25)&amp;nbsp; */&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2013 21:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104015#M21723</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-02-08T21:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: array and loops? recoding into different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104016#M21724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sorry you're right with the recodes&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;0 - &amp;lt; 25 = '0 to &amp;lt; 25'&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;25 -&amp;lt;50 = '25 to &amp;lt;50'&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;50 -&amp;lt;75 = '50 to &amp;lt;75'&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;75 - high='75+'&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Although a format will not work for me, i need the rates recoded into a new array of variables as indicators.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Feb 2013 15:57:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104016#M21724</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2013-02-09T15:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: array and loops? recoding into different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104017#M21725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When forming numeric groups one can usually use the values to calculate the array index.&amp;nbsp; Here I have added a rate5 so the number of rates and the number of groups are not the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input id Rate1 Rate2 Rate3 Rate4 rate5;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 10 23 54 99&lt;BR /&gt;2 18 39 23 84 -5&lt;BR /&gt;3 4 87 92 8 33&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want(drop=i r index rate:);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ARRAY RATELIST {*} RATE1 RATE2 RATE3 RATE4 rate5;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*0-&amp;lt;25, 25-&amp;lt;50, 50-&amp;lt;75, 75-max*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ARRAY NEWCAT {*} R1_0_25 R1_25_50 R1_50_75 R1_75_M &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; R2_0_25 R2_25_50 R2_50_75 R2_75_M &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; R3_0_25 R3_25_50 R3_50_75 R3_75_M&amp;nbsp; &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; R4_0_25 R4_25_50 R4_50_75 R4_75_M&amp;nbsp; &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; R5_0_25 R5_25_50 R5_50_75 R5_75_M ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; do i = 1 to dim(newcat);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newcat{i}=0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do r = 1 to dim(ratelist);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = floor(ratelist{r}/25)+1; /* map rate into a nominal value between 1 and 4 */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = max(i,1);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* map rates&amp;lt;0 to 1*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = min(i,dim(ratelist));&amp;nbsp;&amp;nbsp;&amp;nbsp; /* map large values to upper rate */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; index = i + ((r-1)*4);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* 4 (75/25+1) is number of groups&amp;nbsp; - not number or rates */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newcat{index} = 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Feb 2013 21:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104017#M21725</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2013-02-10T21:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: array and loops? recoding into different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104018#M21726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Art. (I've changed accounts, new company)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code above works for 4 even groups, if i were to have uneven groups, how would that change?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example instead of even 25 percent intervals, i have&lt;/P&gt;&lt;P&gt;0-25&lt;/P&gt;&lt;P&gt;25-40&lt;/P&gt;&lt;P&gt;40-60&lt;/P&gt;&lt;P&gt;60-90&lt;/P&gt;&lt;P&gt;90+&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 14:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104018#M21726</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2013-02-11T14:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: array and loops? recoding into different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104019#M21727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here are a couple of approaches when your groups have unequal width.&amp;nbsp; First an assignment statement - this will be faster than IF-THEN/ELSE processing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; i = 1 * (0 &amp;lt;=ratelist{r} &amp;lt;25)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; +2 * (25&amp;lt;=ratelist{r} &amp;lt;40)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; +3 * (40&amp;lt;=ratelist{r} &amp;lt;60)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; +4 * (60&amp;lt;=ratelist{r} &amp;lt;90)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; +5 * (90&amp;lt;=ratelist{r});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could also create an informat that maps the RATELIST{r} to the index value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;BR /&gt;invalue raterange&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 0 -&amp;lt;25=1&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 25-&amp;lt;40=2&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 40-&amp;lt;60=3&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 60-&amp;lt;90=4&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 90-high=5;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The assignment statement then becomes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = input(ratelist{r},raterange.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the number of ranges becomes much more than 5 I would recommend the format approach.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 23:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104019#M21727</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2013-02-11T23:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: array and loops? recoding into different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104020#M21728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the format approach offers most flexibility as it handles the ranges better than almost all other approaches&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 23:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-loops-recoding-into-different-variables/m-p/104020#M21728</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-02-11T23:24:15Z</dc:date>
    </item>
  </channel>
</rss>

