<?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: Getting the difference in datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648453#M194251</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you post an example which shows the result you are surprised by?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;diff=sales-returns;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Should work fine.&amp;nbsp; If Sales is 0 and Returns is a positive number, Diff will be a negative number, it won't be set to 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;e.g. this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input loan_num sales returns;
datalines;
112 12 0
113 0 10
114 0 0
;run;

data have2;
set have;
diff=sales-returns;
put (sales returns diff)(=) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;returns:&lt;/P&gt;
&lt;PRE&gt;9    data have2;
10   set have;
11   diff=sales-returns;
12   put (sales returns diff)(=) ;
13   run;

sales=12 returns=0 diff=12
sales=0 returns=10 diff=-10
sales=0 returns=0 diff=0
&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;</description>
    <pubDate>Sun, 17 May 2020 23:53:33 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2020-05-17T23:53:33Z</dc:date>
    <item>
      <title>Getting the difference in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648451#M194249</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input loan_num sales returns;&lt;BR /&gt;datalines;&lt;BR /&gt;112 12 0&lt;BR /&gt;113 11 10&lt;BR /&gt;114 9 5&lt;BR /&gt;;run;&lt;/P&gt;
&lt;P&gt;data have2;&lt;BR /&gt;set have;&lt;BR /&gt;&lt;STRONG&gt;diff=sales-returns&lt;/STRONG&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;diff=sales-returns works in this example.&amp;nbsp; In my actual program&amp;nbsp; I created a variable named diff.&amp;nbsp; I subtract sales and returns.&amp;nbsp; Both are defined as numeric.&amp;nbsp; It calculates correctly if both numbers are &amp;gt;0, however if one of the numbers is a 0 the diff is shown as 0 which is incorrect.&amp;nbsp; My question is would there be a different method of subtracting the two variables.&amp;nbsp; Intck is appropriate for dates, not two numerics as shown here.&lt;/P&gt;</description>
      <pubDate>Sun, 17 May 2020 23:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648451#M194249</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2020-05-17T23:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the difference in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648453#M194251</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you post an example which shows the result you are surprised by?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;diff=sales-returns;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Should work fine.&amp;nbsp; If Sales is 0 and Returns is a positive number, Diff will be a negative number, it won't be set to 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;e.g. this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input loan_num sales returns;
datalines;
112 12 0
113 0 10
114 0 0
;run;

data have2;
set have;
diff=sales-returns;
put (sales returns diff)(=) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;returns:&lt;/P&gt;
&lt;PRE&gt;9    data have2;
10   set have;
11   diff=sales-returns;
12   put (sales returns diff)(=) ;
13   run;

sales=12 returns=0 diff=12
sales=0 returns=10 diff=-10
sales=0 returns=0 diff=0
&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;</description>
      <pubDate>Sun, 17 May 2020 23:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648453#M194251</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-05-17T23:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the difference in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648454#M194252</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was playing with your challenge, and its quite difficult to figure out your need as you describe on the text. But I managed to add a new line with a Zero on Sales Variable to check and the behavior is as expected; The Diff calculates properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data have;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;input loan_num sales returns;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;112 12 0&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;112 0 12 /*New Line with Value=Zero on Sales Variable*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;113 11 10&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;114 9 5;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;And When I Check the Execution iteractions all seem well:&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV class="sasSource"&gt;loan_num=112 sales=12 returns=0 diff=12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt;&amp;nbsp; 1st Iteraction is correct&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;loan_num=112 sales=0 returns=12 diff= -12&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; =&amp;gt;&amp;nbsp; 2nd Iteraction is correct&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;loan_num=113 sales=11 returns=10 diff=1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt;&amp;nbsp;&amp;nbsp; 3rd Iteraction is correct&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;loan_num=114 sales=9 returns=5 diff=4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt;&amp;nbsp; 4th Iteraction is also correct&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;Can you please elaborate?&lt;/DIV&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CS&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 00:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648454#M194252</guid>
      <dc:creator>CarlosSpranger</dc:creator>
      <dc:date>2020-05-18T00:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the difference in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648469#M194265</link>
      <description>&lt;P&gt;I had to give the previous example however here is the actual code&lt;/P&gt;
&lt;P&gt;data test(keep=acct_nbr tot_accts_cnt_trn no_act_cnt_ no_acct_ind);&lt;BR /&gt;set dep.cmb1;&lt;BR /&gt;if acct_nbr in('54', '43');&lt;BR /&gt;no_acct_ind=(tot_accts_cnt_trn-no_act_cnt_);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;The output is something like this&lt;/P&gt;
&lt;TABLE width="348"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="72"&gt;ACCT_NBR&lt;/TD&gt;
&lt;TD width="114"&gt;tot_accts_cnt_trn&lt;/TD&gt;
&lt;TD width="81"&gt;no_act_cnt_&lt;/TD&gt;
&lt;TD width="81"&gt;no_acct_ind&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;54&lt;/TD&gt;
&lt;TD&gt;159&lt;/TD&gt;
&lt;TD&gt;17&lt;/TD&gt;
&lt;TD&gt;142&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;54&lt;/TD&gt;
&lt;TD&gt;159&lt;/TD&gt;
&lt;TD&gt;17&lt;/TD&gt;
&lt;TD&gt;142&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;54&lt;/TD&gt;
&lt;TD&gt;159&lt;/TD&gt;
&lt;TD&gt;17&lt;/TD&gt;
&lt;TD&gt;142&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;43&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;43&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;43&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;One thing I notice is that it shows a 0 in the last 2 columns for acct_nbr 43 in sas however when I export to excel it shows a blank value&lt;/P&gt;
&lt;P&gt;Its as if the formula is not working with a 0 exists.&amp;nbsp; I have no idea why this is happening.&amp;nbsp; As you can see it worked for acct_nbr 54&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 02:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648469#M194265</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2020-05-18T02:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the difference in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648471#M194267</link>
      <description>&lt;P&gt;Can you share a sample input related to this last output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I Think the issue resides in your input data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recreated the scenario using proc sql and it works.&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;data have;
input acct_nbr tot_accts_cnt_trn no_act_cnt_ no_acct_ind;
Datalines;
run;

proc sql;
insert into have values (43,1,1,.);
quit;

data test(keep=acct_nbr tot_accts_cnt_trn no_act_cnt_ no_acct_ind);
set have;
no_acct_ind=tot_accts_cnt_trn-no_act_cnt_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="sasSource"&gt;acct_nbr=54 tot_accts_cnt_trn=159 no_act_cnt_=17 no_acct_ind=142&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt; 1st&amp;nbsp; Iteraction&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;acct_nbr=54 tot_accts_cnt_trn=159 no_act_cnt_=17 no_acct_ind=142 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; =&amp;gt; 2nd Iteraction&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;acct_nbr=54 tot_accts_cnt_trn=159 no_act_cnt_=17 no_acct_ind=142 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; =&amp;gt; 3rd Iteraction&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;acct_nbr=43 tot_accts_cnt_trn=1 no_act_cnt_=. no_acct_ind=.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt; 4th Iteraction&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;acct_nbr=43 tot_accts_cnt_trn=1 no_act_cnt_=. no_acct_ind=.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt; 5th Iteraction&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;acct_nbr=43 tot_accts_cnt_trn=1 no_act_cnt_=. no_acct_ind=.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt; 6th Iteraction&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;acct_nbr=43 tot_accts_cnt_trn=1 no_act_cnt_=1 no_acct_ind=0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt; 7th Iteraction&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;
&lt;P&gt;On the one with . which indicate missing values is expected because the subtraction expression should return missing values&lt;/P&gt;
&lt;P&gt;I guest you should do some dta cleansing on input Data.&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;CS&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 18 May 2020 03:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648471#M194267</guid>
      <dc:creator>CarlosSpranger</dc:creator>
      <dc:date>2020-05-18T03:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the difference in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648499#M194279</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you try to reset the missing option? Maybe it is unfortunately set to 0?&lt;/P&gt;
&lt;P&gt;Can you share you code to export to Excel?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing="";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 08:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-difference-in-datastep/m-p/648499#M194279</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-18T08:55:27Z</dc:date>
    </item>
  </channel>
</rss>

