<?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: Replace Missing Data by Calculating the difference between 2 other columns in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607274#M8395</link>
    <description>&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;where&lt;/FONT&gt; statement causes the data step to only read in the records with a missing shipmode, so that is why you do not see any records with a non-missing value for shipmode.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An alternative is to use conditional logic, as below, with an &lt;FONT face="courier new,courier"&gt;if&lt;/FONT&gt; statement, so that all records go to the output data set. I have also updated some of the logic by using &lt;FONT face="courier new,courier"&gt;else&lt;/FONT&gt; as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data apacstore;

set work.apacstore;

   if missing(shipmode) then
   do;
      if shipdate-orderdate &amp;lt;=1 then
         shipmode = 'Same Day';
      else
         if shipdate-orderdate &amp;lt; 3 then
            shipmode = 'First Class';
         else
            if shipdate-orderdate &amp;lt;= 4 then
               shipmode = 'Second Class';
            else
               shipmode = 'Standard Class';
   end;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2019 11:22:05 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2019-11-26T11:22:05Z</dc:date>
    <item>
      <title>Replace Missing Data by Calculating the difference between 2 other columns</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607272#M8394</link>
      <description>&lt;P&gt;Hello All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write a query to replace missing values for the column Shipmode and they have a correlation with the difference of ShipDate and OrderDate.&amp;nbsp; There are 4 types of ShipMode,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Same day&lt;/STRONG&gt; if the ship date and order date are the same, &lt;STRONG&gt;First class&lt;/STRONG&gt; if its below 3 days, &lt;STRONG&gt;Second class&lt;/STRONG&gt; if its below 4 days and everything else is &lt;STRONG&gt;Standard Class&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following query with no luck. It is replacing my original dataset with only the values of those with the missing values. I am an absolute beginner to SAS, so any help on this would be deeply appreciated&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data apacstore;

set work.apacstore;

if shipdate-orderdate &amp;lt;=1 then shipmode = 'Same Day';
if shipdate-orderdate &amp;gt; 1 or shipdate-orderdate &amp;lt; 3 then shipmode = 'First Class';
if shipdate-orderdate &amp;gt;= 3 or shipdate-orderdate &amp;lt;= 4 then shipmode 'Second Class';
if shipdate-orderdate &amp;gt; 4 then shipmode = 'Standard Class';
where shipmode is missing;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ShipModeMissing.png" style="width: 478px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34245i394524242531615A/image-size/large?v=v2&amp;amp;px=999" role="button" title="ShipModeMissing.png" alt="ShipModeMissing.png" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 11:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607272#M8394</guid>
      <dc:creator>Kumarathevan</dc:creator>
      <dc:date>2019-11-26T11:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Missing Data by Calculating the difference between 2 other columns</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607274#M8395</link>
      <description>&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;where&lt;/FONT&gt; statement causes the data step to only read in the records with a missing shipmode, so that is why you do not see any records with a non-missing value for shipmode.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An alternative is to use conditional logic, as below, with an &lt;FONT face="courier new,courier"&gt;if&lt;/FONT&gt; statement, so that all records go to the output data set. I have also updated some of the logic by using &lt;FONT face="courier new,courier"&gt;else&lt;/FONT&gt; as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data apacstore;

set work.apacstore;

   if missing(shipmode) then
   do;
      if shipdate-orderdate &amp;lt;=1 then
         shipmode = 'Same Day';
      else
         if shipdate-orderdate &amp;lt; 3 then
            shipmode = 'First Class';
         else
            if shipdate-orderdate &amp;lt;= 4 then
               shipmode = 'Second Class';
            else
               shipmode = 'Standard Class';
   end;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 11:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607274#M8395</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-11-26T11:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Missing Data by Calculating the difference between 2 other columns</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607535#M8403</link>
      <description>&lt;P&gt;thank you very much. I have a better understanding on how the where statement works now!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 01:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607535#M8403</guid>
      <dc:creator>Kumarathevan</dc:creator>
      <dc:date>2019-11-27T01:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Missing Data by Calculating the difference between 2 other columns</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607536#M8404</link>
      <description>&lt;P&gt;Note that placing the WHERE statement miles away from the SET statement is probably contributing to this type of confusion.&amp;nbsp; It doesn't confuse SAS, but will most certainly confuse programmers looking at the code into the false impression that the WHERE is the last thing that happens.&amp;nbsp; If you want to use WHERE on the way out of the data step use the WHERE= dataset option on the output dataset specification.&lt;/P&gt;
&lt;P&gt;Also clear up your logic in your IF/THEN sequence..&amp;nbsp; Your existing code will only create the first two levels of SHIPMODE, since any number (including missing values) is either greater than 1 or it isn't.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data apacstore(where=(shipmode is missing;));
  set work.apacstore;
  if (shipdate-orderdate) &amp;gt;.Z AND (shipdate-orderdate) &amp;lt;=1 then shipmode = 'Same Day';
  else if (shipdate-orderdate) &amp;gt; 1 AND (shipdate-orderdate) &amp;lt; 3 then shipmode = 'First Class';
  else if (shipdate-orderdate) &amp;gt;= 3 AND (shipdate-orderdate) &amp;lt;= 4 then shipmode 'Second Class';
  else if shipdate-orderdate &amp;gt; 4 then shipmode = 'Standard Class';
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 01:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607536#M8404</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-27T01:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Missing Data by Calculating the difference between 2 other columns</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607539#M8406</link>
      <description>Thank You Tom! really appreciate your insights on these best practices. I am a total noob trying to complete an assignment here. Learning tonnes through this forum!</description>
      <pubDate>Wed, 27 Nov 2019 01:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Replace-Missing-Data-by-Calculating-the-difference-between-2/m-p/607539#M8406</guid>
      <dc:creator>Kumarathevan</dc:creator>
      <dc:date>2019-11-27T01:58:02Z</dc:date>
    </item>
  </channel>
</rss>

