<?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: Need assistance with how to alter data using a IF-THEN ELSE loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-assistance-with-how-to-alter-data-using-a-IF-THEN-ELSE-loop/m-p/541812#M149672</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/261011"&gt;@daft22&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your posted code you don't have a set statement in your recode step, so instead of recoding values in the original data set HW, you replace the existing HW with a new data set with one observation and one variable containing a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you refer to "none of the data", which means that you ran your code with a set statement, but didn't get the desired result. That is because Homework1 is already defined as numeric, so you cannot change it to 'A'. You get a missing value and a note about invalid numeric data.&amp;nbsp;If you want to recode data instead of using a format, you must create new grade-variables to hold the character values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please always post the log. I gues it looks like this:&lt;/P&gt;
&lt;PRE&gt;21
22   DATA HW; set HW;
23   IF Homework1 &amp;gt;= 90 THEN DO;
24   Homework1 = 'A';
25   END;
26   RUN;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      24:13
NOTE: Invalid numeric data, 'A' , at line 24 column 13.
Homework1=. Homework2=30 _ERROR_=1 _N_=1
NOTE: There were 1 observations read from the data set WORK.HW.
NOTE: The data set WORK.HW has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           4.55 seconds
      cpu time            0.14 seconds
&lt;/PRE&gt;
&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Mar 2019 12:42:20 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2019-03-10T12:42:20Z</dc:date>
    <item>
      <title>Need assistance with how to alter data using a IF-THEN ELSE loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-assistance-with-how-to-alter-data-using-a-IF-THEN-ELSE-loop/m-p/541776#M149649</link>
      <description>&lt;P&gt;Good Evening,&lt;BR /&gt;&lt;BR /&gt;I am trying to alter a table which has homework scores by replacing the numerical scores with letter grades.&amp;nbsp;&lt;BR /&gt;My Current code looks as such:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DATA HW;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;INFILE '/folders/myfolders/sasuser.v94/HomeworkData.txt' FIRSTOBS=2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;INPUT Name :$8. Homework1 Homework2 Homework3 Homework4 Homework5;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;RUN;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;PROC PRINT DATA=HW;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;RUN;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DATA HW;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;IF Homework1 &amp;gt;= 90 THEN DO;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Homework1 = 'A';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;END;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;PROC PRINT DATA=HW;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;So far, none of the data in the first column that has a numerical value of 90 or higher is actually converting into an 'A' grade.&lt;BR /&gt;Am I missing something?&lt;BR /&gt;&lt;BR /&gt;Thank you!!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;PS. First column is for the names of the 'students'&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Mar 2019 03:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-assistance-with-how-to-alter-data-using-a-IF-THEN-ELSE-loop/m-p/541776#M149649</guid>
      <dc:creator>daft22</dc:creator>
      <dc:date>2019-03-10T03:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need assistance with how to alter data using a IF-THEN ELSE loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-assistance-with-how-to-alter-data-using-a-IF-THEN-ELSE-loop/m-p/541782#M149653</link>
      <description>&lt;P&gt;SAS provides FORMATS as a way to display letter grades AND to keep the underlying numbers. Try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value grade
low - 49 = "F"
50 - 59 = "E"
60 - 69 = "D"
70 - 79 = "C"
80 - 89 = "B"
90 - high = "A";
run;

DATA HW;
INFILE '/folders/myfolders/sasuser.v94/HomeworkData.txt' FIRSTOBS=2;
INPUT Name :$8. Homework1 - Homework5;
format Homework1 - Homework5 grade.;
RUN;

proc print data=HW; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That way you can count the number of students for each letter grade in a class (with proc freq) but also the average grade for the class (proc means), with the same data.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Mar 2019 04:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-assistance-with-how-to-alter-data-using-a-IF-THEN-ELSE-loop/m-p/541782#M149653</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-10T04:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need assistance with how to alter data using a IF-THEN ELSE loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-assistance-with-how-to-alter-data-using-a-IF-THEN-ELSE-loop/m-p/541812#M149672</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/261011"&gt;@daft22&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your posted code you don't have a set statement in your recode step, so instead of recoding values in the original data set HW, you replace the existing HW with a new data set with one observation and one variable containing a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you refer to "none of the data", which means that you ran your code with a set statement, but didn't get the desired result. That is because Homework1 is already defined as numeric, so you cannot change it to 'A'. You get a missing value and a note about invalid numeric data.&amp;nbsp;If you want to recode data instead of using a format, you must create new grade-variables to hold the character values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please always post the log. I gues it looks like this:&lt;/P&gt;
&lt;PRE&gt;21
22   DATA HW; set HW;
23   IF Homework1 &amp;gt;= 90 THEN DO;
24   Homework1 = 'A';
25   END;
26   RUN;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      24:13
NOTE: Invalid numeric data, 'A' , at line 24 column 13.
Homework1=. Homework2=30 _ERROR_=1 _N_=1
NOTE: There were 1 observations read from the data set WORK.HW.
NOTE: The data set WORK.HW has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           4.55 seconds
      cpu time            0.14 seconds
&lt;/PRE&gt;
&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Mar 2019 12:42:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-assistance-with-how-to-alter-data-using-a-IF-THEN-ELSE-loop/m-p/541812#M149672</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-03-10T12:42:20Z</dc:date>
    </item>
  </channel>
</rss>

