<?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 Indexing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588403#M168151</link>
    <description>&lt;P&gt;I am trying to print an index between 1 and 4 for different conditions but my code is not working. Here is my code:&lt;/P&gt;&lt;P&gt;DATA cars.inx;&lt;BR /&gt;set Cars1;&lt;BR /&gt;Where Size=SMALL; DO;&lt;BR /&gt;If (0&amp;lt;Mileage&amp;lt;=20 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=1;&lt;BR /&gt;else if (0&amp;lt;Mileage&amp;lt;=20 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=2;&lt;BR /&gt;else if (21&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=3;&lt;BR /&gt;else if (21&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=4;&lt;BR /&gt;end;&lt;BR /&gt;Where Size = COMPACT; DO;&lt;BR /&gt;If (0&amp;lt;Mileage&amp;lt;=15 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=1;&lt;BR /&gt;else if (0&amp;lt;Mileage&amp;lt;=15 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=2;&lt;BR /&gt;else if (16&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=3;&lt;BR /&gt;else if (16&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=4;&lt;BR /&gt;end;&lt;BR /&gt;Where Size= MID-SIZED; DO;&lt;BR /&gt;If (0&amp;lt;Mileage&amp;lt;=12 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=1;&lt;BR /&gt;else if (0&amp;lt;Mileage&amp;lt;=12 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=2;&lt;BR /&gt;else if (13&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=3;&lt;BR /&gt;else if (13&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=4;&lt;BR /&gt;end;&lt;BR /&gt;proc print; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone see where I am going wrong?&lt;/P&gt;</description>
    <pubDate>Thu, 12 Sep 2019 23:20:38 GMT</pubDate>
    <dc:creator>HALOBEAST999</dc:creator>
    <dc:date>2019-09-12T23:20:38Z</dc:date>
    <item>
      <title>Indexing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588403#M168151</link>
      <description>&lt;P&gt;I am trying to print an index between 1 and 4 for different conditions but my code is not working. Here is my code:&lt;/P&gt;&lt;P&gt;DATA cars.inx;&lt;BR /&gt;set Cars1;&lt;BR /&gt;Where Size=SMALL; DO;&lt;BR /&gt;If (0&amp;lt;Mileage&amp;lt;=20 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=1;&lt;BR /&gt;else if (0&amp;lt;Mileage&amp;lt;=20 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=2;&lt;BR /&gt;else if (21&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=3;&lt;BR /&gt;else if (21&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=4;&lt;BR /&gt;end;&lt;BR /&gt;Where Size = COMPACT; DO;&lt;BR /&gt;If (0&amp;lt;Mileage&amp;lt;=15 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=1;&lt;BR /&gt;else if (0&amp;lt;Mileage&amp;lt;=15 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=2;&lt;BR /&gt;else if (16&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=3;&lt;BR /&gt;else if (16&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=4;&lt;BR /&gt;end;&lt;BR /&gt;Where Size= MID-SIZED; DO;&lt;BR /&gt;If (0&amp;lt;Mileage&amp;lt;=12 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=1;&lt;BR /&gt;else if (0&amp;lt;Mileage&amp;lt;=12 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=2;&lt;BR /&gt;else if (13&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=3;&lt;BR /&gt;else if (13&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=4;&lt;BR /&gt;end;&lt;BR /&gt;proc print; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone see where I am going wrong?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 23:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588403#M168151</guid>
      <dc:creator>HALOBEAST999</dc:creator>
      <dc:date>2019-09-12T23:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588407#M168153</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290002"&gt;@HALOBEAST999&lt;/a&gt;&amp;nbsp; &amp;nbsp;Welcome to SAS communities.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the correction below and see if this works&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA cars.inx;
set Cars1;
if Size='SMALL' then DO;
If (0&amp;lt;Mileage&amp;lt;=20 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=1;
else if (0&amp;lt;Mileage&amp;lt;=20 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=2;
else if (21&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=3;
else if (21&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=4;
end;
else if Size = 'COMPACT' then DO;
If (0&amp;lt;Mileage&amp;lt;=15 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=1;
else if (0&amp;lt;Mileage&amp;lt;=15 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=2;
else if (16&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=3;
else if (16&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=4;
end;
else if  Size= 'MID-SIZED' then DO;
If (0&amp;lt;Mileage&amp;lt;=12 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=1;
else if (0&amp;lt;Mileage&amp;lt;=12 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=2;
else if (13&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=3;
else if (13&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=4;
end;
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Sep 2019 23:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588407#M168153</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-12T23:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588408#M168154</link>
      <description>&lt;P&gt;You should post your data as well. By the looks of it, you should use if-then-do statements instead of where.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where size=small; do --&amp;gt; "if size = 'small' then do"; then "else if size = 'compact' then do;"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 23:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588408#M168154</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2019-09-12T23:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588411#M168156</link>
      <description>&lt;P&gt;As mentioned, you are using the WHERE statement wrongly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Read the documentation: &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"The WHERE&amp;nbsp;&lt;/SPAN&gt;statement&amp;nbsp;selects observations in&amp;nbsp;SAS&amp;nbsp;data sets only"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;See&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1xbr9r0s9veq0n137iftzxq4g7e.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1xbr9r0s9veq0n137iftzxq4g7e.htm&amp;amp;docsetVersion=9.4&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here, you have 3 where clauses, so the latest clause is &lt;U&gt;applied when reading the data&lt;/U&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 00:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588411#M168156</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-09-13T00:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588481#M168194</link>
      <description>&lt;P&gt;The code that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;gave you should work fine, but it seems to me that there is a lot of code duplication. Maybe you should try something like this (not tested, as you did not provide any data):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue mileage
    'SMALL'=20
    'COMPACT'=15
    'MID-SIZED'=12
    ;
run;

data cars.inx;
  set cars;
  _mileage_=input(size,mileage.);
  If (0&amp;lt;Mileage&amp;lt;=_mileage_ &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=1;
  else if (0&amp;lt;Mileage&amp;lt;=_mileage_ &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=2;
  else if (_mileage_+1&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=Reliable&amp;lt;=3) then index=3;
  else if (_mileage_+1&amp;lt;=Mileage&amp;lt;=50 &amp;amp; 4&amp;lt;=Reliable&amp;lt;=5) then index=4;
  drop _mileage_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 11:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588481#M168194</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-09-13T11:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588538#M168216</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290002"&gt;@HALOBEAST999&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;'s idea of making the code shorter. Depending on the data you might even go a step further in that direction:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cars.inx(drop=_s);
set cars1;
_s=whichc(size,'SMALL','COMPACT','MID-SIZED');
if 0&amp;lt;mileage&amp;lt;=50 &amp;amp; 1&amp;lt;=reliable&amp;lt;=5 &amp;amp; _s then index=2*(mileage&amp;gt;choosen(_s,20,15,12))+(reliable&amp;gt;3)+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes integer values for &lt;FONT face="courier new,courier"&gt;mileage&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;reliable&lt;/FONT&gt;, but this is strongly suggested by your IF conditions anyway.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 14:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing/m-p/588538#M168216</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-09-13T14:28:20Z</dc:date>
    </item>
  </channel>
</rss>

