<?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: macrovariable created in macro used in proc sgplot in same macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macrovariable-created-in-macro-used-in-proc-sgplot-in-same-macro/m-p/393033#M94626</link>
    <description>&lt;P&gt;fail.1. your macro variable assignment statement 'happens' before the data step is processed.&lt;/P&gt;&lt;P&gt;fail.2. b is a (local) data set variable, which cannot be used in a global statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;use call symput which does what you want: create a macro variable with the value of the data step variable b;&lt;/P&gt;&lt;P&gt;this assignment happens after the data step completes, thus the &lt;FONT face="courier new,courier"&gt;run&lt;/FONT&gt; statement in this code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%local b;&lt;BR /&gt;call symputx('b',b);&lt;BR /&gt;run;&lt;BR /&gt;%put echo &amp;amp;=b;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;hth&lt;/P&gt;&lt;P&gt;Ron Fehd&amp;nbsp; global, or local, maven&lt;/P&gt;</description>
    <pubDate>Mon, 04 Sep 2017 18:51:15 GMT</pubDate>
    <dc:creator>Ron_MacroMaven</dc:creator>
    <dc:date>2017-09-04T18:51:15Z</dc:date>
    <item>
      <title>macrovariable created in macro used in proc sgplot in same macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macrovariable-created-in-macro-used-in-proc-sgplot-in-same-macro/m-p/393025#M94625</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;new day new question. This time I want to calculate bandwidth of a histogram inside a makro which also creates the histogram. Here is some data I'm using:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data plot;
 do i =1 to 1000;
 y = rannor(1234) ;
 y1 = rannor(1235) ;

 output;
 end;
 run;
 
data varCorr;
input correlation ;
   datalines;
    4
    ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The data is the used in the macro:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO createPlot(dataPlot, varCorr, obs ); 
  data bandwidth;
  set &amp;amp;varCorr;
  b = 3.5 * y/(&amp;amp;obs**(1/3));
  %let b = %SYSEVALF(b);
proc sgplot data=&amp;amp;dataPlot;
  histogram y / binwidth=b transparency=0.5;
  histogram y1 / binwidth=b transparency=0.5;           
  density y / type=kernel lineattrs=GraphData1;  
  density y1 / type=kernel lineattrs=GraphData2;  
  xaxis label="bla" ;
  keylegend "yK" "yG" / across=1 position=TopRight location=Inside;
run;
%MEND;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to calculate the b first and use it later in the proc sgplot when plotting the histogram.&lt;/P&gt;&lt;P&gt;I think the problem is in this line:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %let b = %SYSEVALF(b);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I cannot figure it out how to fix it by myself.&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 06:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macrovariable-created-in-macro-used-in-proc-sgplot-in-same-macro/m-p/393025#M94625</guid>
      <dc:creator>mrer</dc:creator>
      <dc:date>2017-09-05T06:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: macrovariable created in macro used in proc sgplot in same macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macrovariable-created-in-macro-used-in-proc-sgplot-in-same-macro/m-p/393033#M94626</link>
      <description>&lt;P&gt;fail.1. your macro variable assignment statement 'happens' before the data step is processed.&lt;/P&gt;&lt;P&gt;fail.2. b is a (local) data set variable, which cannot be used in a global statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;use call symput which does what you want: create a macro variable with the value of the data step variable b;&lt;/P&gt;&lt;P&gt;this assignment happens after the data step completes, thus the &lt;FONT face="courier new,courier"&gt;run&lt;/FONT&gt; statement in this code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%local b;&lt;BR /&gt;call symputx('b',b);&lt;BR /&gt;run;&lt;BR /&gt;%put echo &amp;amp;=b;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;hth&lt;/P&gt;&lt;P&gt;Ron Fehd&amp;nbsp; global, or local, maven&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2017 18:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macrovariable-created-in-macro-used-in-proc-sgplot-in-same-macro/m-p/393033#M94626</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2017-09-04T18:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: macrovariable created in macro used in proc sgplot in same macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macrovariable-created-in-macro-used-in-proc-sgplot-in-same-macro/m-p/393091#M94649</link>
      <description>&lt;P&gt;This part of your code does not make any sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bandwidth;
  set &amp;amp;varCorr;
  b = 3.5 * y/(&amp;amp;obs**(1/3));
  %let b = %SYSEVALF(b);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The %LET macro assignment statement will happen while the macro processor is processsing the code so it is the same as if you wrote it this way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let b = %SYSEVALF(b);
data bandwidth;
  set &amp;amp;varCorr;
  b = 3.5 * y/(&amp;amp;obs**(1/3));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which of course still makes no sense as the letter B will not be evaluated to anything by the %SYSEVALF() macro function.&lt;/P&gt;
&lt;P&gt;Also no where in your code to make any reference to this macro variable B that you were trying to calculate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;You need to know what code you want to generate before you start using macro logic to generate code.&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Looks like you want to combine your two datasets, calculate something and then plot it. &amp;nbsp;But you haven't given us enough information to know how to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example your code references a variable named Y1 that is not defined anywhere.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 03:31:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macrovariable-created-in-macro-used-in-proc-sgplot-in-same-macro/m-p/393091#M94649</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-05T03:31:00Z</dc:date>
    </item>
  </channel>
</rss>

