<?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: macro variable with comma in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906459#M357933</link>
    <description>&lt;P&gt;In SAS SQL when no format is specified for a&amp;nbsp; variable length the format defaults to best8.&lt;BR /&gt;This was causing anything beyond 8 characters to be truncated. Therefore the proper approach is to use format as rightly suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Dec 2023 14:55:48 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2023-12-06T14:55:48Z</dc:date>
    <item>
      <title>macro variable with comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906451#M357927</link>
      <description>&lt;P&gt;I don't understand why the generated macro variable is not printed with decimal values, but only the integer part:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
x=16017854.36;
run;

proc sql noprint;
select x into:x from test;
quit;
%put x=&amp;amp;x.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Dec 2023 14:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906451#M357927</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2023-12-06T14:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable with comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906454#M357930</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select x format=12.2 into :x from test;
quit;
%put &amp;amp;=x;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Dec 2023 14:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906454#M357930</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-12-06T14:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable with comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906459#M357933</link>
      <description>&lt;P&gt;In SAS SQL when no format is specified for a&amp;nbsp; variable length the format defaults to best8.&lt;BR /&gt;This was causing anything beyond 8 characters to be truncated. Therefore the proper approach is to use format as rightly suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 14:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906459#M357933</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-12-06T14:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable with comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906479#M357938</link>
      <description>&lt;P&gt;Something to always keep in mind: the SAS macro language is text. So any "number" requires you to take control to create the needed text representation of the numeric value, i.e.&amp;nbsp; a format most of the time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also use of values with decimal portions are likely to require the macro function %SYSEVALF to actually use the decimal portion. Consider this brief example of attempting to add 10 to a decimal valued macro variable:&lt;/P&gt;
&lt;PRE&gt;%let value= 123.45;

%let newvalue_1 = %eval(&amp;amp;value. + 10);
%let newvalue_2 = %sysevalf(&amp;amp;value. + 10);

%put newvalue_1 is: &amp;amp;newvalue_1.  and  newvalue_2 is: &amp;amp;newvalue_2.;
&lt;/PRE&gt;
&lt;P&gt;Note that without %eval or %sysevalf you would get text of "123.45 + 10", not the arithmetic value.&lt;/P&gt;
&lt;P&gt;The log:&lt;/P&gt;
&lt;PRE&gt;1    %let value= 123.45;
2
3    %let newvalue_1 = %eval(&amp;amp;value. + 10);
ERROR: A character operand was found in the %EVAL function or %IF
       condition where a numeric operand is required. The condition was:
       123.45 + 10
4    %let newvalue_2 = %sysevalf(&amp;amp;value. + 10);
5
6    %put newvalue_1 is: &amp;amp;newvalue_1.  and  newvalue_2 is: &amp;amp;newvalue_2.;
newvalue_1 is:   and  newvalue_2 is: 133.45

&lt;/PRE&gt;
&lt;P&gt;You might ask why did I use %eval. That is what SAS will by default call internally if you attempt a number of uses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also find this of use:&lt;/P&gt;
&lt;PRE&gt;%macro dummy(value);
%if &amp;amp;value. &amp;gt; 1000 %then %put value is greater than 1000;
%else %put value is not greater than 1000;
%mend;

%dummy(123);
%dummy(123.45);&lt;/PRE&gt;
&lt;P&gt;With result&lt;/P&gt;
&lt;PRE&gt;40   %dummy(123);
value is not greater than 1000
41   %dummy(123.45);
value is greater than 1000
&lt;/PRE&gt;
&lt;P&gt;and wonder why that second result?&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;42   %dummy(abc);
value is greater than 1000
&lt;/PRE&gt;
&lt;P&gt;Remember my comment about macros and text? When using a value that represents an integer&amp;nbsp; with the comparison you get SAS %eval result&amp;nbsp; because it works as SAS is attempting to help you. But when the value is not an integer the comparison is&amp;nbsp; CHARACTER based. Since the second character 2 is "greater than" 0 then the comparison stops and is "greater than" using character rules. And the same with abc. "a" is greater than "1".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the sort of thing that happens to generate unexpected results in the macro language when you test code and it "works" then use with other ranges of values such as testing with integers and then actual values are decimal.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 15:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906479#M357938</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-06T15:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable with comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906493#M357944</link>
      <description>&lt;P&gt;Alternatively, you can use CALL SYMPUTX in data step, which passes your decimals and long numeric values (up to 17 I believe) into macro variable without truncation.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	x=16017854.36;
	call symputx('x', x); 
run;
%put &amp;amp;=x; &lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;log:&lt;/P&gt;
&lt;PRE&gt;X=16017854.36&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Dec 2023 16:20:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-with-comma/m-p/906493#M357944</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-12-06T16:20:56Z</dc:date>
    </item>
  </channel>
</rss>

