<?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 computation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312895#M67909</link>
    <description>Yes, I may don't need to have a macro, I wonder how I can use the result of different macro for further computation.&lt;BR /&gt;(Unfortunately, I don't have proc IML)&lt;BR /&gt;/*macro A*/&lt;BR /&gt;%macro A(dataset, Y, X);&lt;BR /&gt;%global A;&lt;BR /&gt;proc sql ;&lt;BR /&gt;select mean(abs(&amp;amp;Y- &amp;amp;X)) format 20.3 into :A from &amp;amp;dataset;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;/*macro B, the input data for B is different from A*/&lt;BR /&gt;%macro B(dataset, Y, X,n);&lt;BR /&gt;%global B;&lt;BR /&gt;proc sql ;&lt;BR /&gt;select sqrt(1-(1-( 1 - mean ( (&amp;amp;Y- &amp;amp;X)**2 )/ mean (( (select mean(&amp;amp;Y) from &amp;amp;dataset)- &amp;amp;X)**2 )))*((count(1) - 1)/(count(1) - 1 - &amp;amp;n))) format 20.3 into :B from &amp;amp;dataset;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;/*macro A &amp;amp; B, are working correctly, however I have to use the result of booth these two macro in another macro, I need some data preparation for A &amp;amp; B inside the third macro and then run the loop */&lt;BR /&gt;%macro C;&lt;BR /&gt;array m{*} m1-m&amp;amp;k;&lt;BR /&gt;%DO i = 1 %TO &amp;amp;k;&lt;BR /&gt;m{i} = %A/%B;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;</description>
    <pubDate>Sun, 20 Nov 2016 14:56:34 GMT</pubDate>
    <dc:creator>Marzi</dc:creator>
    <dc:date>2016-11-20T14:56:34Z</dc:date>
    <item>
      <title>macro computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312876#M67894</link>
      <description>&lt;P&gt;Dear All;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What the general rule for Macro computation?&lt;BR /&gt;I searched on the&amp;nbsp;web&amp;nbsp;and found some example which described the Macro variable trough the&lt;BR /&gt;%let&lt;BR /&gt;&lt;SPAN&gt;%SYSEVALF&lt;BR /&gt;%put&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;, however still is not clear for me the exact rule.&lt;BR /&gt;&lt;BR /&gt;this is what I want to compute:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do i = 1 to k;&lt;BR /&gt;output{i} = %macro A/%macro B;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;End;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;the output of both A &amp;amp; B is an integer&amp;nbsp;and I need to save the above command in a loop with k run, means finally my output should be &amp;nbsp;a matrix(array) with k row and 1 column.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 13:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312876#M67894</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-20T13:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: macro computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312878#M67895</link>
      <description>&lt;P&gt;Sounds a bit like your trying to use macros as functions - they're not. If you want a function use PROC FCMP.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A do loop as written should be using an array, amd will generate k columns and 1 row, not k rows and 1 column.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Matices aren't really what you should be aiming for, in SAS Base it's variables and rows. If you want matrix functionality use PROC IML&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect you don't need a macro but can't say without further information. .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 14:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312878#M67895</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-20T14:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: macro computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312880#M67897</link>
      <description>&lt;P&gt;To answer your initial question as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%Let -&amp;gt; creates macro variables. There are other ways as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%SYSEVALF -&amp;gt; doing floating point calculations that would require SYSFUNC as well, allows you,to skip one step&lt;/P&gt;
&lt;P&gt;%PUT -&amp;gt; displays information in the log&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These run the gamut of macro statements/functionality so it's hard to see what you're asking&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation is fairly thorough and again can't point to specifics without knowing what you're trying to do in more detail. The appendix contains about 13 examples of commonly written macros.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#p0rmrcca06xibcn1w7eynijd7ir7.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#p0rmrcca06xibcn1w7eynijd7ir7.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 14:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312880#M67897</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-20T14:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: macro computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312895#M67909</link>
      <description>Yes, I may don't need to have a macro, I wonder how I can use the result of different macro for further computation.&lt;BR /&gt;(Unfortunately, I don't have proc IML)&lt;BR /&gt;/*macro A*/&lt;BR /&gt;%macro A(dataset, Y, X);&lt;BR /&gt;%global A;&lt;BR /&gt;proc sql ;&lt;BR /&gt;select mean(abs(&amp;amp;Y- &amp;amp;X)) format 20.3 into :A from &amp;amp;dataset;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;/*macro B, the input data for B is different from A*/&lt;BR /&gt;%macro B(dataset, Y, X,n);&lt;BR /&gt;%global B;&lt;BR /&gt;proc sql ;&lt;BR /&gt;select sqrt(1-(1-( 1 - mean ( (&amp;amp;Y- &amp;amp;X)**2 )/ mean (( (select mean(&amp;amp;Y) from &amp;amp;dataset)- &amp;amp;X)**2 )))*((count(1) - 1)/(count(1) - 1 - &amp;amp;n))) format 20.3 into :B from &amp;amp;dataset;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;/*macro A &amp;amp; B, are working correctly, however I have to use the result of booth these two macro in another macro, I need some data preparation for A &amp;amp; B inside the third macro and then run the loop */&lt;BR /&gt;%macro C;&lt;BR /&gt;array m{*} m1-m&amp;amp;k;&lt;BR /&gt;%DO i = 1 %TO &amp;amp;k;&lt;BR /&gt;m{i} = %A/%B;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;</description>
      <pubDate>Sun, 20 Nov 2016 14:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312895#M67909</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-20T14:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: macro computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312898#M67911</link>
      <description>&lt;P&gt;I think it would be beneficial to step back, explain what you're trying to do and post sample input and desired output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can probably wrangle your code into working but it but it won't be efficient and even as a learning exercise probably not that useful. You may need a macro but it's hard to tell right now.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 15:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312898#M67911</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-20T15:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: macro computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312944#M67932</link>
      <description>&lt;P&gt;SAS macros are mostly used when you want to convert "static" code to "dynamic" code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My rule of thumb for macros:&lt;/P&gt;
&lt;P&gt;1. First make the code work in a static version (=don't use macro coding at all)&lt;/P&gt;
&lt;P&gt;2. Only use macro coding if you can't do it with normal Base SAS code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can clearly tell us what you have (ideally providing a sample data set created via a SAS data step) and then explain us what you need (ideally also posting a desired output/result), then I'm sure someone here in this forum can help you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's really hard to do, is to give you answers based on some most likely not properly working macro code without any data, any log and not even knowing what you actually want to achieve.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 23:18:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312944#M67932</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-11-20T23:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: macro computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312961#M67935</link>
      <description>&lt;P&gt;Based on just a quick analaysis, here's a recommendation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, run %A and %B outside of %C. &amp;nbsp;That will create &amp;amp;A and &amp;amp;B. &amp;nbsp;Then inside %C, refer to &amp;amp;A and &amp;amp;B instead of %A and %B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that doesn't solve the problem, then you're probably looking to do something more complex where %A and %B generate results that vary rather than being constant. &amp;nbsp;That would require a different approach.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 02:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312961#M67935</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-21T02:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: macro computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312962#M67936</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;, yes, %A and %B are not constant and within each Do loop their value are changing.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 04:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312962#M67936</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-21T04:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: macro computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312973#M67937</link>
      <description>&lt;P&gt;Then if you still need assistance, please explain what you're trying to do and what you have versus what you need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 07:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312973#M67937</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-21T07:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: macro computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312992#M67946</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;, somehow, I figure out my question, I replace the macro %A and %B with other methods such that by now, I have a matrix with two columns, then is much easier to divide column 1 by column 2 and save it in the&amp;nbsp;loop.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 09:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-computation/m-p/312992#M67946</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-21T09:21:50Z</dc:date>
    </item>
  </channel>
</rss>

