<?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: calculate difference between character numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-between-character-numbers/m-p/725368#M225299</link>
    <description>&lt;P&gt;Maxim 2: Read the Log.&lt;/P&gt;
&lt;P&gt;You will find NOTEs about automatic conversion of character to numeric and back.&lt;/P&gt;
&lt;P&gt;To do reliable calculations, convert to numeric explicitly. The conversion back to character can be done implicitly by using the CATS function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input _name_ :$10. var1 :$15. var2 :$15.;
datalines;
mean(sd)  76.4(11.39) 77.2(8.63)
min,max 40.0,113.0  50.0,106.0
;

data want;
set have;
if _name_="min,max"
then var_want = cats(
  input(scan(var1,1,","),best.) - input(scan(var2,1,","),best.),
  ",",
  input(scan(var1,2,","),best.) - input(scan(var2,2,","),best.)
);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also please note how I presented your data in a data step with datalines; please do so yourself in the future, as others can easily recreate a dataset with a simple copy/paste and submit, without any doubts about variable types, attributes and content.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Mar 2021 08:22:51 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-03-11T08:22:51Z</dc:date>
    <item>
      <title>calculate difference between character numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-between-character-numbers/m-p/725366#M225298</link>
      <description>&lt;P&gt;Hi I have two variables with descriptive statistics and I need to calculate the difference between them&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_name_&lt;/TD&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;var_want&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mean(sd)&lt;/TD&gt;&lt;TD&gt;76.4(11.39)&lt;/TD&gt;&lt;TD&gt;77.2(8.63)&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;min,max&lt;/TD&gt;&lt;TD&gt;40.0,113.0&lt;/TD&gt;&lt;TD&gt;50.0,106.0&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i've tried this,example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if _name_="min,max" then var_want=substr(var,1,2)-substr(var2,1,2)||","||substr(var,6,3)-substr(var2,6,3)&lt;/P&gt;&lt;P&gt;but it doesn't work cause 40-50=-10 and sas cannot convert it to char (invalid numeric data)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there a simple way to calculate the difference between var1 and var2 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 08:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-between-character-numbers/m-p/725366#M225298</guid>
      <dc:creator>Jedrzej</dc:creator>
      <dc:date>2021-03-11T08:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference between character numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-between-character-numbers/m-p/725368#M225299</link>
      <description>&lt;P&gt;Maxim 2: Read the Log.&lt;/P&gt;
&lt;P&gt;You will find NOTEs about automatic conversion of character to numeric and back.&lt;/P&gt;
&lt;P&gt;To do reliable calculations, convert to numeric explicitly. The conversion back to character can be done implicitly by using the CATS function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input _name_ :$10. var1 :$15. var2 :$15.;
datalines;
mean(sd)  76.4(11.39) 77.2(8.63)
min,max 40.0,113.0  50.0,106.0
;

data want;
set have;
if _name_="min,max"
then var_want = cats(
  input(scan(var1,1,","),best.) - input(scan(var2,1,","),best.),
  ",",
  input(scan(var1,2,","),best.) - input(scan(var2,2,","),best.)
);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also please note how I presented your data in a data step with datalines; please do so yourself in the future, as others can easily recreate a dataset with a simple copy/paste and submit, without any doubts about variable types, attributes and content.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 08:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-between-character-numbers/m-p/725368#M225299</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-11T08:22:51Z</dc:date>
    </item>
  </channel>
</rss>

