<?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: sum variables to create new variables and missing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330548#M74187</link>
    <description>&lt;P&gt;Use the below code. I added one more condition. Since your first condition checks for any values less or equal to 10 the nulls/missing falls into that bucket. You can correct it by checking for them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
input sale cost ;
Diff=sale-cost ;
 if diff &amp;lt;= 10 and diff &amp;gt; 0 then Change="LOW";
     else if 10 &amp;lt; diff &amp;lt;= 20 then Change="MED";
     else Change="HI";
datalines ;
. 10.23
15 3.72
17.23 .
;
run ;

proc print data=have ;run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Feb 2017 17:31:07 GMT</pubDate>
    <dc:creator>anoopmohandas7</dc:creator>
    <dc:date>2017-02-07T17:31:07Z</dc:date>
    <item>
      <title>sum variables to create new variables and missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330533#M74175</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a new variable called "Diff" by subtracting two columns. When&amp;nbsp;those columns have missing variables, I want diff to be missing too. In a data step, I tried "diff = sales-cost;" and got an error. Then I tried "diff=sum(sales,-cost);" which worked but gave me values for all of diff, when there should be some missing. I want it to look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sales &amp;nbsp; &amp;nbsp; cost &amp;nbsp; &amp;nbsp; diff&lt;/P&gt;&lt;P&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8.99 &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and right now it looks like:&lt;/P&gt;&lt;P&gt;sales &amp;nbsp; &amp;nbsp; cost &amp;nbsp; &amp;nbsp; &amp;nbsp;diff&lt;/P&gt;&lt;P&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8.99 &amp;nbsp; &amp;nbsp;-8.99&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330533#M74175</guid>
      <dc:creator>Lnicholl</dc:creator>
      <dc:date>2017-02-07T17:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: sum variables to create new variables and missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330534#M74176</link>
      <description>&lt;P&gt;What's the error you are getting. I ran the sample code and I get the output as you wanted.&lt;/P&gt;&lt;P&gt;Also refer the difference between sum statement and sum variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/30677244/difference-between-sum-statement-and-sum-variable-in-sas" target="_blank"&gt;http://stackoverflow.com/questions/30677244/difference-between-sum-statement-and-sum-variable-in-sas&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
input sale cost ;
Diff=sale-cost ;
datalines ;
. 10.23
15 3.72
17.23 .
;
run ;

proc print data=have ;run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330534#M74176</guid>
      <dc:creator>anoopmohandas7</dc:creator>
      <dc:date>2017-02-07T17:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: sum variables to create new variables and missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330537#M74177</link>
      <description>&lt;P&gt;Thank you! Now I am using "diff=price-sales;" and it works, however I still need to have missing values in diff if price or sales is missing&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330537#M74177</guid>
      <dc:creator>Lnicholl</dc:creator>
      <dc:date>2017-02-07T17:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: sum variables to create new variables and missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330538#M74178</link>
      <description>You will continue to get it if you use price-sales. Are you facing any issues now ? I mean not getting missing values when prices/sales is missing ?</description>
      <pubDate>Tue, 07 Feb 2017 17:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330538#M74178</guid>
      <dc:creator>anoopmohandas7</dc:creator>
      <dc:date>2017-02-07T17:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: sum variables to create new variables and missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330539#M74179</link>
      <description>&lt;P&gt;Yes--right now I am not getting any missing values in diff. I want missing values&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330539#M74179</guid>
      <dc:creator>Lnicholl</dc:creator>
      <dc:date>2017-02-07T17:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: sum variables to create new variables and missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330541#M74181</link>
      <description>&lt;P&gt;please show a case where you use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; diff=sales-priice&lt;/P&gt;
&lt;P&gt;and you fail to get diff=. when either sales or price (or both) is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... unless you have a subsequent "diff=' assignment later in the program.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330541#M74181</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-07T17:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: sum variables to create new variables and missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330542#M74182</link>
      <description>&lt;P&gt;I do reference diff again, as I am making another categorical variable called "change"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data prices;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;input unitcostprice unitsalesprice;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;diff = unitsalesprice - unitcostprice;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if diff &amp;lt;= 10 then Change="LOW";&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;else if 10 &amp;lt; diff &amp;lt;= 20 then Change="MED";&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;else Change="HI";&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;There are no missing values for change and I want there to be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330542#M74182</guid>
      <dc:creator>Lnicholl</dc:creator>
      <dc:date>2017-02-07T17:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: sum variables to create new variables and missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330545#M74184</link>
      <description>&lt;P&gt;Diff is missing,&amp;nbsp;&amp;nbsp;but missing values compare low to all valid numerics (like 10). So change='LOW'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if not(missing(diff)) and diff &amp;lt; 10 then change='LOW';&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330545#M74184</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-07T17:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: sum variables to create new variables and missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330548#M74187</link>
      <description>&lt;P&gt;Use the below code. I added one more condition. Since your first condition checks for any values less or equal to 10 the nulls/missing falls into that bucket. You can correct it by checking for them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
input sale cost ;
Diff=sale-cost ;
 if diff &amp;lt;= 10 and diff &amp;gt; 0 then Change="LOW";
     else if 10 &amp;lt; diff &amp;lt;= 20 then Change="MED";
     else Change="HI";
datalines ;
. 10.23
15 3.72
17.23 .
;
run ;

proc print data=have ;run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:31:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330548#M74187</guid>
      <dc:creator>anoopmohandas7</dc:creator>
      <dc:date>2017-02-07T17:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: sum variables to create new variables and missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330576#M74196</link>
      <description>&lt;P&gt;You do need to change the logic, but don't do it this way.&amp;nbsp; All the missing values for DIFF will be classified as "HI".&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 18:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-variables-to-create-new-variables-and-missing/m-p/330576#M74196</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-07T18:53:22Z</dc:date>
    </item>
  </channel>
</rss>

