<?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: Creating new variables with many if statements - How to shorten it? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-variables-with-many-if-statements-How-to-shorten-it/m-p/403686#M278951</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    resultsnum=indexc('FDCBA',results)-1;
    if resultsnum&amp;lt;0 then resultsnum=.;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 12 Oct 2017 20:15:48 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-10-12T20:15:48Z</dc:date>
    <item>
      <title>Creating new variables with many if statements - How to shorten it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-variables-with-many-if-statements-How-to-shorten-it/m-p/403670#M278949</link>
      <description>&lt;P&gt;I want a new variable that contains the number version of their grade. How can I can I do this with less code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data students5 ;&lt;BR /&gt;set students4 ;&lt;BR /&gt;if results = 'A' then resultsNum = 4 ;&lt;BR /&gt;if results = 'B' then resultsNum = 3 ;&lt;BR /&gt;if results = 'C' then resultsNum = 2 ;&lt;BR /&gt;if results = 'D' then resultsNum = 1 ;&lt;BR /&gt;if results = 'F' then resultsNum = 0 ;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 19:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-variables-with-many-if-statements-How-to-shorten-it/m-p/403670#M278949</guid>
      <dc:creator>UCFtigers2017</dc:creator>
      <dc:date>2017-10-12T19:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variables with many if statements - How to shorten it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-variables-with-many-if-statements-How-to-shorten-it/m-p/403677#M278950</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/170667"&gt;@UCFtigers2017&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;You certainly should use ELSE as well.&lt;/P&gt;
&lt;P&gt;As an alternative: Create a format and then use this format on your variable&amp;nbsp;&lt;EM&gt;result&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 20:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-variables-with-many-if-statements-How-to-shorten-it/m-p/403677#M278950</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-12T20:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variables with many if statements - How to shorten it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-variables-with-many-if-statements-How-to-shorten-it/m-p/403686#M278951</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    resultsnum=indexc('FDCBA',results)-1;
    if resultsnum&amp;lt;0 then resultsnum=.;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2017 20:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-variables-with-many-if-statements-How-to-shorten-it/m-p/403686#M278951</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-12T20:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variables with many if statements - How to shorten it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-variables-with-many-if-statements-How-to-shorten-it/m-p/403828#M278952</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/170667"&gt;@UCFtigers2017&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;Unless you can shorten the code to a formula, as suggested by mkeintz, I would consider using a SELECT statement here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data students5 ;
  set students4 ;
  select(results);
    when('A') resultsNum = 4 ;
    when('B') resultsNum = 3 ;
    when('C') resultsNum = 2 ;
    when('D') resultsNum = 1 ;
    when('F') resultsNum = 0 ;
    otherwise;
    end;
run;&lt;/PRE&gt;&lt;P&gt;Or you could use an informat:&lt;/P&gt;&lt;PRE&gt;proc format;
  invalue graden
    'A'=4
    'B'=3
    'C'=2
    'D'=1
    'F'=0
    other=.;
run;

data students5;
  set students4;
  resultsNum=input(results,graden.);
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Oct 2017 08:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-variables-with-many-if-statements-How-to-shorten-it/m-p/403828#M278952</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-10-13T08:05:45Z</dc:date>
    </item>
  </channel>
</rss>

