<?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: How to evaluate a macro variable after variable was created in proc summary? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342408#M272857</link>
    <description>My solution in  creates a variable meany rom a macro variable that can be used in the datastep.&lt;BR /&gt;&lt;BR /&gt;You could use the meany to compare against the individual Ys.</description>
    <pubDate>Sun, 19 Mar 2017 22:03:17 GMT</pubDate>
    <dc:creator>rogerjdeangelis</dc:creator>
    <dc:date>2017-03-19T22:03:17Z</dc:date>
    <item>
      <title>How to evaluate a macro variable after variable was created in proc summary?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342401#M272854</link>
      <description>&lt;P&gt;How to evaluate a macro variable after variable was created in proc summary? &amp;nbsp;SEE BELOW&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data summaryOut; set summaryOut;&lt;BR /&gt;file print;&lt;BR /&gt;put meanY; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;meanY is in summaryOut dataset. I want a function to evaluate meanY (=23083).&lt;BR /&gt;data _null_; set summaryOut;&lt;BR /&gt;%let meanY=%SYSFUNC(meanY);&lt;BR /&gt;%put &amp;amp;meanY;&lt;BR /&gt;*meanY=23083.164953;&lt;BR /&gt;run; quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;87 data _null_; set summaryOut;&lt;BR /&gt;88 %let meanY=%EVAVL(meanY);&lt;BR /&gt;ERROR: Expected open parenthesis after macro function name not found.&lt;BR /&gt;89 %put &amp;amp;meanY;&lt;BR /&gt;SYMBOLGEN: Macro variable MEANY resolves to&lt;BR /&gt;91 run;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Mar 2017 21:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342401#M272854</guid>
      <dc:creator>MaryA_Marion</dc:creator>
      <dc:date>2017-03-19T21:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to evaluate a macro variable after variable was created in proc summary?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342405#M272855</link>
      <description>&lt;P&gt;So far, you don't have a macro variable holding any meaningful information. &amp;nbsp;PROC SUMMARY does not create macro variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first DATA step shows the value of a DATA step variable MEANY. &amp;nbsp;If you want to get that value into a macro variable, you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set summaryOut;&lt;/P&gt;
&lt;P&gt;call symputx('meany', meany);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;meanY;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gives you a macro variable holding the contents of the DATA step variable.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Mar 2017 21:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342405#M272855</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-19T21:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to evaluate a macro variable after variable was created in proc summary?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342407#M272856</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;How to evaluate a macro variable after variable was created in proc summary?

inspired by
https://goo.gl/hPzyHa
https://communities.sas.com/t5/General-SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342401


HAVE
====

Up to 40 obs WORK.CLASS total obs=5

Obs     Y

 1     14
 2     13
 3     13
 4     14
 5     14

WANT ( Something like this )
============================

  data _null_;
   set summaryout
   meany = &amp;amp;meany;
   put " then mean of y is " meany;
 run;quit;

FULL SOLUTION
=============

data class;
 set sashelp.class(keep=age obs=5 rename=age=y);
run;quit;

proc summary data=class;
var y;
output out=summaryout(keep=meany) mean=meanY;
run;quit;

Up to 40 obs from summaryout total obs=1

Obs     MEANY

 1      13.6


%symdel mac_meany;
data _null_;
 * create macro variable from summaryout;
 if _n_=0 then do;
     %let rc=%sysfunc(dosubl('
        data _null_;
          set summaryout;
          call symputx("mac_meany",put(meany,best.),"G");
        run;quit;
    '));
    %put &amp;amp;=mac_meany;
  end;

  meany = &amp;amp;mac_meany;

  put " The mean of y is " meany;

run;quit;

The mean of y is 13.6

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Mar 2017 22:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342407#M272856</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-19T22:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to evaluate a macro variable after variable was created in proc summary?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342408#M272857</link>
      <description>My solution in  creates a variable meany rom a macro variable that can be used in the datastep.&lt;BR /&gt;&lt;BR /&gt;You could use the meany to compare against the individual Ys.</description>
      <pubDate>Sun, 19 Mar 2017 22:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342408#M272857</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-19T22:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to evaluate a macro variable after variable was created in proc summary?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342416#M272858</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16492"&gt;@MaryA_Marion&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;How to evaluate a macro variable after variable was created in proc summary? &amp;nbsp;SEE BELOW&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data summaryOut; set summaryOut;&lt;BR /&gt;file print;&lt;BR /&gt;put meanY; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;meanY is in summaryOut dataset. I want a function to evaluate meanY (=23083).&lt;BR /&gt;data _null_; set summaryOut;&lt;BR /&gt;%let meanY=%SYSFUNC(meanY);&lt;BR /&gt;%put &amp;amp;meanY;&lt;BR /&gt;*meanY=23083.164953;&lt;BR /&gt;run; quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;87 data _null_; set summaryOut;&lt;BR /&gt;88 %let meanY=%EVAVL(meanY);&lt;BR /&gt;ERROR: Expected open parenthesis after macro function name not found.&lt;BR /&gt;89 %put &amp;amp;meanY;&lt;BR /&gt;SYMBOLGEN: Macro variable MEANY resolves to&lt;BR /&gt;91 run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unfortunately your code doesn't make sense.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you're trying to create a macro variable for a mean and then use it in another step. Rather than a macro, a merge works as well, depending on usage of course.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Add average value to a dataset;
*Solution 1 - PROC MEANS + Data step;

proc means data=sashelp.class noprint;
    output out=avg_values mean(height)=avg_height;
run;

data class;
    set sashelp.class;

    if _n_=1 then
        set avg_values;
run;

proc print data=class;
run;

*Solution 2 - PROC SQL - note the warning in the log;
PROC SQL;
Create table want as
select *, mean(height) as avg_height
from sashelp.class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Mar 2017 23:08:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-evaluate-a-macro-variable-after-variable-was-created-in/m-p/342416#M272858</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-19T23:08:23Z</dc:date>
    </item>
  </channel>
</rss>

