<?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: arithmetic operation using macro variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/arithmetic-operation-using-macro-variables/m-p/214895#M39657</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you're looking for something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let pc = %syseval&lt;STRONG&gt;f &lt;/STRONG&gt;( (&amp;amp;partn / &amp;amp;totaln)*100);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You may want to round the result to desired number of decimals such as&lt;/P&gt;&lt;P&gt;%let pc = %sysfunc(round(&amp;amp;pc, 0.01));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 31 Jul 2015 17:23:39 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2015-07-31T17:23:39Z</dc:date>
    <item>
      <title>arithmetic operation using macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arithmetic-operation-using-macro-variables/m-p/214894#M39656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have two macro variables that correctly resolved from the following PROC SQL functions. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(*) as Total into :totaln from test1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(*) as Total into :partn from test2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although they are both macro (character) variables, in essence they are numeric constants from which I am interested in calculating a percentage: pc = (partn/totaln )* 100.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro pc;&lt;/P&gt;&lt;P&gt;%let totaln=%left(&amp;amp;totaln);&lt;/P&gt;&lt;P&gt;%let partn=%left(&amp;amp;partn);&lt;/P&gt;&lt;P&gt;t=inputn(&amp;amp;totaln,8.);&lt;/P&gt;&lt;P&gt;p=inputn(&amp;amp;partn,8.);&lt;/P&gt;&lt;P&gt;%let pc=%syseval((p/t)*100);&lt;/P&gt;&lt;P&gt;title "Percent represented: &amp;amp;pc.% ";&lt;/P&gt;&lt;P&gt;%mend pc;&lt;/P&gt;&lt;P&gt;%pc;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The above attempt did not work. The macro does not let me create a constant t or p and gives me an error message: ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;How do I turn&amp;nbsp; macro character to numeric variable to perform an arithmetic operation?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 15:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arithmetic-operation-using-macro-variables/m-p/214894#M39656</guid>
      <dc:creator>sonicpoem</dc:creator>
      <dc:date>2015-07-31T15:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: arithmetic operation using macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arithmetic-operation-using-macro-variables/m-p/214895#M39657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you're looking for something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let pc = %syseval&lt;STRONG&gt;f &lt;/STRONG&gt;( (&amp;amp;partn / &amp;amp;totaln)*100);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You may want to round the result to desired number of decimals such as&lt;/P&gt;&lt;P&gt;%let pc = %sysfunc(round(&amp;amp;pc, 0.01));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 17:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arithmetic-operation-using-macro-variables/m-p/214895#M39657</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-31T17:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: arithmetic operation using macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arithmetic-operation-using-macro-variables/m-p/214896#M39658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you.&amp;nbsp; It worked! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 18:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arithmetic-operation-using-macro-variables/m-p/214896#M39658</guid>
      <dc:creator>sonicpoem</dc:creator>
      <dc:date>2015-07-31T18:16:31Z</dc:date>
    </item>
  </channel>
</rss>

