<?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 Sum 2 macro variables with format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858888#M339356</link>
    <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know, please, how to to sum 2 macro variables with € format ? For exemple, if I have in &amp;amp;TOTAL_S 1 € and in&amp;nbsp; &amp;amp;TOTAL2_Another_2 3 €, the sum in &amp;amp;TOTAL_SUP2 must be 4 €.&lt;/P&gt;
&lt;P&gt;In case when the table is empty (no observation), how to create the macro variable with 0 value ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code is :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options locale=FR;

data matable_bis;
	set matable (obs=1);
	TOTAL2=propcase((put(TOTAL,NLMNLEUR12.0)));
	keep TOTAL TOTAL2;
run;

/***if my table matableenPlus2 is empty (no observation),
how to create the macrovariable ? ***/

data matableenPlus2;
	set matableenPlus;
	TOTAL2_Another=propcase((put(Another_total,NLMNLEUR12.0)));
	keep TOTAL2_Another;
run;


proc sql noprint;
	select TOTAL2 into : TOTAL_S from matable_bis;
quit;

proc sql noprint;
	select TOTAL2_Another into : TOTAL2_Another_S from matableenPlus2;
quit;

/****How to sum 2 macro variables with format ? ***/
%let TOTAL_SUPP2 = %sysfunc(&amp;amp;TOTAL_S., &amp;amp;TOTAL2_Another_S.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thank you for your help !&lt;/P&gt;</description>
    <pubDate>Wed, 15 Feb 2023 10:11:41 GMT</pubDate>
    <dc:creator>SASdevAnneMarie</dc:creator>
    <dc:date>2023-02-15T10:11:41Z</dc:date>
    <item>
      <title>Sum 2 macro variables with format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858888#M339356</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know, please, how to to sum 2 macro variables with € format ? For exemple, if I have in &amp;amp;TOTAL_S 1 € and in&amp;nbsp; &amp;amp;TOTAL2_Another_2 3 €, the sum in &amp;amp;TOTAL_SUP2 must be 4 €.&lt;/P&gt;
&lt;P&gt;In case when the table is empty (no observation), how to create the macro variable with 0 value ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code is :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options locale=FR;

data matable_bis;
	set matable (obs=1);
	TOTAL2=propcase((put(TOTAL,NLMNLEUR12.0)));
	keep TOTAL TOTAL2;
run;

/***if my table matableenPlus2 is empty (no observation),
how to create the macrovariable ? ***/

data matableenPlus2;
	set matableenPlus;
	TOTAL2_Another=propcase((put(Another_total,NLMNLEUR12.0)));
	keep TOTAL2_Another;
run;


proc sql noprint;
	select TOTAL2 into : TOTAL_S from matable_bis;
quit;

proc sql noprint;
	select TOTAL2_Another into : TOTAL2_Another_S from matableenPlus2;
quit;

/****How to sum 2 macro variables with format ? ***/
%let TOTAL_SUPP2 = %sysfunc(&amp;amp;TOTAL_S., &amp;amp;TOTAL2_Another_S.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thank you for your help !&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 10:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858888#M339356</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2023-02-15T10:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 2 macro variables with format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858889#M339357</link>
      <description>&lt;P&gt;Can you post an example of what the two macro variables look like?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 09:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858889#M339357</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2023-02-15T09:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 2 macro variables with format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858890#M339358</link>
      <description>&lt;P&gt;Why do you go to such lengths to store the values as character with a currency format when you later need the raw numeric values?&lt;/P&gt;
&lt;P&gt;Anyway, you can always use the original variables in the SELECT INTO without a format.&lt;/P&gt;
&lt;P&gt;Which value do you want in case there's no observations? Zero or missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 10:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858890#M339358</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-15T10:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 2 macro variables with format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858892#M339359</link>
      <description>&lt;P&gt;Thank you for your answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I specify : I would like to improve my code : I need to sum another variable.&lt;/P&gt;
&lt;P&gt;So, I have the code that calculate the total, after I put the total in € format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, I need to add to this total another total, I'm wondering if I can sum 2 macro variables.&lt;/P&gt;
&lt;P&gt;Another problem : when I calculat another total, sometimes I can have no values in the tables (empty table), in this case I woul like to add 0.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 10:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858892#M339359</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2023-02-15T10:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 2 macro variables with format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858894#M339360</link>
      <description>Thank you for the message, I added the information to the message.</description>
      <pubDate>Wed, 15 Feb 2023 10:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858894#M339360</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2023-02-15T10:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 2 macro variables with format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858901#M339361</link>
      <description>&lt;P&gt;Repeating what has already been said:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data matable_bis;
	set matable (obs=1);
	TOTAL2=propcase((put(TOTAL,NLMNLEUR12.0)));
	keep TOTAL TOTAL2;
run;

/***if my table matableenPlus2 is empty (no observation),
how to create the macrovariable ? ***/

data matableenPlus2;
	set matableenPlus;
	TOTAL2_Another=propcase((put(Another_total,NLMNLEUR12.0)));
	keep TOTAL2_Another;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do the sum on data set variables TOTAL and ANOTHER_TOTAL, do not sum macro variables that have characters in them.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 11:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/858901#M339361</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-15T11:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 2 macro variables with format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/859015#M339412</link>
      <description>&lt;P&gt;Of course you can sum macro variables,&amp;nbsp;if they contain&amp;nbsp;&lt;U&gt;numbers&lt;/U&gt; in a programming sense (only digits, a decimal dot, and possibly a leading sign). That's why you MUST use the unformatted values.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 18:05:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/859015#M339412</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-15T18:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 2 macro variables with format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/859030#M339416</link>
      <description>&lt;P&gt;You run into 2 problems with that format. One is that the COMMA that may get placed in the value (national language settings) means that would be treated as a delimiter by the macro language. Then just having the currency symbol means that the result is not treated as a number even with the proper function calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example using US currency as but Euros will do the same. Note the conversion note only shows PART of the VAL1 in the error message. That is because of the comma in the value.&lt;/P&gt;
&lt;PRE&gt;80   %let val1 = $123,456.77;
81   %let val2 = $45.12;
82
83   %let sum= %sysevalf(&amp;amp;val1. + &amp;amp;val2.);
ERROR: Unknown %SYSEVALF conversion operand '456.77 + $45.12' specified; conversion is terminated.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: $123
84   /* error so no value*/
85
86
87   %let val11 = 123456.77;
88   %let val22 = 45.12;
89
90   %let sum2= %sysevalf(&amp;amp;val11. + &amp;amp;val22.);
91   %put sum is: &amp;amp;sum2.;
sum is: 123501.89

&lt;/PRE&gt;
&lt;P&gt;%sysfunc is going to require at least one data step function, such as SUM, but still will fail because of the currency symbols.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 18:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-2-macro-variables-with-format/m-p/859030#M339416</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-15T18:46:24Z</dc:date>
    </item>
  </channel>
</rss>

