<?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: Convert a Macro Variable Value to Numeric Format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Macro-Variable-Value-to-Numeric-Format/m-p/404540#M98337</link>
    <description>&lt;P&gt;You want PUT, not INPUT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also have scope issues, ie is the macro variable global or local.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let &amp;amp;invar = %sysfunc(putn(&amp;amp;&amp;amp;&amp;amp;invar,&amp;amp;infmt));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Oct 2017 18:20:21 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-10-16T18:20:21Z</dc:date>
    <item>
      <title>Convert a Macro Variable Value to Numeric Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Macro-Variable-Value-to-Numeric-Format/m-p/404536#M98336</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Hi. I want to convert a macro variable value, which is all numerals (which is character text, of course) to a numeric format. I followed &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Chris Yindra's insightful paper "%SYSFUNC - The Brave New Macro World" but am not successful. Chris has the following example, which I can replicate to work:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; MYDATE = 971006;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; NOTE: original value: &amp;amp;MYDATE.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; chngfmt(invar,infmt);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; &amp;amp;invar = &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(inputn(&amp;amp;&amp;amp;&amp;amp;invar,&amp;amp;infmt));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; chngfmt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;%&lt;STRONG&gt;&lt;I&gt;chngfmt&lt;/I&gt;&lt;/STRONG&gt;(MYDATE,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;YYMMDD6.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; NOTE: sas data value: &amp;amp;MYDATE.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;But, I want to convert to a simple comma format. Typically, I want to display the row count in output with commas. My code looks like the following, but does not change the format (I used a %let statement in my example for simplicity):&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; row_count=10000;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; NOTE: original value: &amp;amp;row_count.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; chngfmt(invar,infmt);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; &amp;amp;invar = &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(inputn(&amp;amp;&amp;amp;&amp;amp;invar,&amp;amp;infmt));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; chngfmt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;%&lt;STRONG&gt;&lt;I&gt;chngfmt&lt;/I&gt;&lt;/STRONG&gt;(row_count,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;comma15.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; NOTE: sas data value: &amp;amp;row_count.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;Any suggestions?&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 18:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-Macro-Variable-Value-to-Numeric-Format/m-p/404536#M98336</guid>
      <dc:creator>CurtisSmithDCAA</dc:creator>
      <dc:date>2017-10-16T18:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a Macro Variable Value to Numeric Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Macro-Variable-Value-to-Numeric-Format/m-p/404540#M98337</link>
      <description>&lt;P&gt;You want PUT, not INPUT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also have scope issues, ie is the macro variable global or local.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let &amp;amp;invar = %sysfunc(putn(&amp;amp;&amp;amp;&amp;amp;invar,&amp;amp;infmt));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 18:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-Macro-Variable-Value-to-Numeric-Format/m-p/404540#M98337</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-16T18:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a Macro Variable Value to Numeric Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Macro-Variable-Value-to-Numeric-Format/m-p/404546#M98339</link>
      <description>&lt;P&gt;Thanks. I was tinkering with putn before but could not get it to work. But, with your encouragement, tried it again and viola!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 18:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-Macro-Variable-Value-to-Numeric-Format/m-p/404546#M98339</guid>
      <dc:creator>CurtisSmithDCAA</dc:creator>
      <dc:date>2017-10-16T18:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a Macro Variable Value to Numeric Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Macro-Variable-Value-to-Numeric-Format/m-p/404554#M98340</link>
      <description>&lt;P&gt;To format the number with commas you want to use the comma FORMAT, not the comma INFORMAT.&lt;/P&gt;
&lt;P&gt;If you are going to have macro variables with values in formatted style then perhaps your macro should include both an INFORMAT and FORMAT. That way you could read in YYMMDD values and output DATE9 values, for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's build in some debugging logic for our testing here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro chngfmt(invar,infmt,outfmt,debug=0);
%if (&amp;amp;debug) %then %put Input value: %superq(&amp;amp;invar);
%let &amp;amp;invar = %sysfunc(inputn(%superq(&amp;amp;invar),&amp;amp;infmt),&amp;amp;outfmt);
%if (&amp;amp;debug) %then %put Result value: %superq(&amp;amp;invar);
%mend chngfmt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then your examples might look like this.&lt;/P&gt;
&lt;PRE&gt;7004   %LET MYDATE = 971006;
7005   %chngfmt(MYDATE,YYMMDD6,debug=1);
Input value: 971006
Result value: 13793
7006
7007   %let row_count=10000;
7008   %chngfmt(row_count,f32,comma15,debug=1);
Input value: 10000
Result value: 10,000
7009
7010   %chngfmt(MYDATE,F32,DATE9,debug=1);
Input value: 13793
Result value: 06OCT1997
7011   %chngfmt(row_count,comma15,debug=1);
Input value: 10,000
Result value: 10000
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 19:23:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-Macro-Variable-Value-to-Numeric-Format/m-p/404554#M98340</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-16T19:23:29Z</dc:date>
    </item>
  </channel>
</rss>

