<?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: Subtracting one numeric value from another in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-one-numeric-value-from-another/m-p/603423#M174826</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/298230"&gt;@jcochrane424&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Did you look at your input data after you created the data set? Your INPUT statement is messed up: It inputs DATE twice, and AGE_GROUP is read a a numeric variable while it's chock full of alphas. A correct input step, given your data, could look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                             
  infile cards dlm=',' ;                                                                                                                
  input date :8. gender :$20. age_group :$25. population_in_thousands ;                                                                 
  format population_in_thousands comma10. ;                                                                                             
  cards ;                                                                                                                               
2015,both sexes,65 years and over,47695                                                                                                 
2015,both sexes,85 years and over,6306                                                                                                  
2015,female,    65 years and over,26654                                                                                                 
2015,female,    85 years and over,4143                                                                                                  
2015,male,      65 years and over,21041                                                                                                 
2015,male,      85 years and over,2163                                                                                                  
;                                                                                                                                       
run ;       
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can't expect correct output from incorrect input: It's otherwise known as GIGO. Now rerun your code against the correct input, and if you should have any incongruences you don't anticipate, ask about them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Nov 2019 03:39:15 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-11-12T03:39:15Z</dc:date>
    <item>
      <title>Subtracting one numeric value from another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-one-numeric-value-from-another/m-p/603418#M174824</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I'm having a little trouble in SAS 9.4. I'm working with projected population data from 2015 to 2050.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data I'm working with looks as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;infile&lt;/SPAN&gt; datalines dlm&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;','&lt;/SPAN&gt; dsd&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;date :$8. date&lt;/SPAN&gt; :&lt;SPAN class="token punctuation"&gt;$10&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; gender :&lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;20&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; age_group :&lt;SPAN class="token number"&gt;25&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; population_in_thousands&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; population_in_thousands comma10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;2015,both sexes,65 years and over,47695&lt;BR /&gt;2015,both sexes,85 years and over,6306&lt;BR /&gt;2015,female,65 years and over,26654&lt;BR /&gt;2015,female,85 years and over,4143&lt;BR /&gt;2015,male,65 years and over,21041&lt;BR /&gt;2015,male,85 years and over,2163&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Here's an the code I have so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data New_projected_pop;&lt;BR /&gt;do until (last.date and last.gender);&lt;BR /&gt;set work.proj_pop_removebadages;&lt;BR /&gt;by date gender;&lt;BR /&gt;select (Age_group);&lt;BR /&gt;when ("85 years and over") over85 = population_in_thousands;&lt;BR /&gt;otherwise;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;do until (last.date and last.gender);&lt;BR /&gt;set work.proj_pop_removebadages;&lt;BR /&gt;by date gender;&lt;BR /&gt;if Age_group = "65 years and over" and nmiss(over85) = 0&lt;BR /&gt;then population_in_thousands = population_in_thousands - over85;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I'm looking at the results of the code, it groups by date and only by the male gender, so the over85 column for each year of the projected pop. data is only subtracting the male value of the "85 years and over'" from the number for the "65 years and over" records. So in the example data it would be subtracting 2163 from the "65 years and over" values for all genders, not just male. I also know that the over85 column must be dropped, but have just been keeping it to check the results. If anyone knows how to group by gender as well so that it doesn't only look at the male value that would be great! Hopefully I've provided enough detail.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 02:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-one-numeric-value-from-another/m-p/603418#M174824</guid>
      <dc:creator>jcochrane424</dc:creator>
      <dc:date>2019-11-12T02:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting one numeric value from another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-one-numeric-value-from-another/m-p/603423#M174826</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/298230"&gt;@jcochrane424&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Did you look at your input data after you created the data set? Your INPUT statement is messed up: It inputs DATE twice, and AGE_GROUP is read a a numeric variable while it's chock full of alphas. A correct input step, given your data, could look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                             
  infile cards dlm=',' ;                                                                                                                
  input date :8. gender :$20. age_group :$25. population_in_thousands ;                                                                 
  format population_in_thousands comma10. ;                                                                                             
  cards ;                                                                                                                               
2015,both sexes,65 years and over,47695                                                                                                 
2015,both sexes,85 years and over,6306                                                                                                  
2015,female,    65 years and over,26654                                                                                                 
2015,female,    85 years and over,4143                                                                                                  
2015,male,      65 years and over,21041                                                                                                 
2015,male,      85 years and over,2163                                                                                                  
;                                                                                                                                       
run ;       
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can't expect correct output from incorrect input: It's otherwise known as GIGO. Now rerun your code against the correct input, and if you should have any incongruences you don't anticipate, ask about them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 03:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-one-numeric-value-from-another/m-p/603423#M174826</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-12T03:39:15Z</dc:date>
    </item>
  </channel>
</rss>

