<?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 not populating variables expected in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452996#M114383</link>
    <description>&lt;P&gt;You put the DATA statement and RUN statement in the wrong place. Put them around the macro calls.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro freq (table,ord, sord);
if &amp;amp;table then do;
  ord=&amp;amp;ord;
  sord=&amp;amp;sord;
end; 
%mend freq;

data freqs ;
  set allae (in=a) allsae (in=b) alldlt  (in=c) anyae (in=d) 
      anyteg3 (in=e) anyrte (in=f) anyg3rte (in=g) anysae (in=h) 
      anyrsae (in=i) anyrsg3s (in=j) anydlt (in=k) anydisc (in=l) 
      anyinter (in=m) anyreduc (in=n) anyfaed (in=o) anyfrae (in=p)
  ;
  by tx;
%freq (a,1,1);
%freq (b,2,1);
%freq (c,3,1);
...
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 10 Apr 2018 23:06:31 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-04-10T23:06:31Z</dc:date>
    <item>
      <title>macro not populating variables expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452957#M114366</link>
      <description>&lt;P&gt;Hi all!&amp;nbsp; I need a little help trouble shooting this program.&amp;nbsp; basically, I need the ORD and SORD variables to populate with a number depending on the table name.&amp;nbsp; &amp;nbsp; I am currently getting all null values because the last table has zero obs (its a freq table).&amp;nbsp; So I think I'm missing a loop or something so it's not overwriting?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if table=A then ORD=1 and SORD=1;&lt;/P&gt;
&lt;P&gt;If table=P then ORD=4 and SORD=14;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro freq (table,ord, sord);
data freqs ;
set allae (in=a) allsae (in=b) alldlt  (in=c) anyae (in=d) anyteg3 (in=e) anyrte (in=f) anyg3rte (in=g) anysae (in=h) anyrsae (in=i) anyrsg3s (in=j)
anydlt (in=k) anydisc (in=l) anyinter (in=m) anyreduc (in=n) anyfaed (in=o) anyfrae (in=p);
by tx;
if &amp;amp;table then do;
	ord=&amp;amp;ord;
	sord=&amp;amp;sord;
	end; 
run;
%mend freq;

%freq (a,1,1);
%freq (b,2,1);
%freq (c,3,1);
%freq (d,4,2);
%freq (e,4,3);
%freq (f,4,4);
%freq (g,4,5);
%freq (h,4,6);
%freq (i,4,7);
%freq (j,4,8);
%freq (k,4,9);
%freq (l,4,10);
%freq (m,4,11);
%freq (n,4,12);
%freq (o,4,13);
%freq (p,4,14);


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Help is appreciated!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 21:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452957#M114366</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2018-04-10T21:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: macro not populating variables expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452961#M114368</link>
      <description>&lt;P&gt;Do any of those data sets already have variables named any of a through p?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do realize that each run of the macro replaces the previous data set don't you? And the last data set probably has null values for most of the records since your "p" data set comes after a whole bunch.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you test this an get a proper result with only two input sets before adding the other dozen or so?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the purpose of this macro? The name Freqs is pretty misleading as nothing is counted and no "frequencies" are generated?&lt;/P&gt;
&lt;P&gt;It usually helps to provide a little bit of example input data (maybe 5 records from each of the first 2 or 3 data sets) and what the desired result for those records would be. Only include as many variables as needed to make things clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 21:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452961#M114368</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-10T21:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: macro not populating variables expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452962#M114369</link>
      <description>&lt;P&gt;Yes, I just realized the last dataset is overwritting. These are all frequency tables I need to build a RTF table. So I need to set the orders. I can do this the log way with 'output' but is there a way to do the repetitive step for all these stacked tables without it overwriting?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;long way...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if a then do;&lt;BR /&gt; ord=1;&lt;BR /&gt; sord=1&lt;BR /&gt; end;&lt;BR /&gt;if b then do;&lt;BR /&gt; ord=2;&lt;BR /&gt; sord=1&lt;BR /&gt; end; &lt;BR /&gt;if c then do;&lt;BR /&gt; ord=3;&lt;BR /&gt; sord=1&lt;BR /&gt; end;&lt;/P&gt;
&lt;P&gt;etc.....&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 21:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452962#M114369</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2018-04-10T21:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: macro not populating variables expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452970#M114375</link>
      <description>&lt;P&gt;You probably need some sort of macro loop OR not a macro at all.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm inclined to go down the not a macro route at all. In that case, I'd probably generate some variables I could join on or lookup or possibly a format instead. At the end of the day, it's a lookup problem.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 21:30:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452970#M114375</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-10T21:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: macro not populating variables expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452988#M114379</link>
      <description>&lt;P&gt;A "least amount of change" approach would be to change the definition of the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro freqs (table, ord, sord);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if &amp;amp;table then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ord=&amp;amp;ord;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; sord=&amp;amp;sord;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;%mend freqs;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then begin with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; freqs &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; allae &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; allsae &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; alldlt  &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;c&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anyae &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;d&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anyteg3 &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;e&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anyrte &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;f&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anyg3rte &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;g&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anysae &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;h&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anyrsae &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anyrsg3s &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;j&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;
anydlt &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;k&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anydisc &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;l&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anyinter &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;m&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anyreduc &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anyfaed &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;o&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; anyfrae &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;p&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; tx&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then call all the macros just as you are doing now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then add:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 22:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452988#M114379</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-10T22:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: macro not populating variables expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452996#M114383</link>
      <description>&lt;P&gt;You put the DATA statement and RUN statement in the wrong place. Put them around the macro calls.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro freq (table,ord, sord);
if &amp;amp;table then do;
  ord=&amp;amp;ord;
  sord=&amp;amp;sord;
end; 
%mend freq;

data freqs ;
  set allae (in=a) allsae (in=b) alldlt  (in=c) anyae (in=d) 
      anyteg3 (in=e) anyrte (in=f) anyg3rte (in=g) anysae (in=h) 
      anyrsae (in=i) anyrsg3s (in=j) anydlt (in=k) anydisc (in=l) 
      anyinter (in=m) anyreduc (in=n) anyfaed (in=o) anyfrae (in=p)
  ;
  by tx;
%freq (a,1,1);
%freq (b,2,1);
%freq (c,3,1);
...
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Apr 2018 23:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/452996#M114383</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-10T23:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: macro not populating variables expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/453007#M114386</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/59697"&gt;@jenim514&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Yes, I just realized the last dataset is overwritting. These are all frequency tables I need to build a RTF table. So I need to set the orders. I can do this the log way with 'output' but is there a way to do the repetitive step for all these stacked tables without it overwriting?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;long way...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if a then do;&lt;BR /&gt; ord=1;&lt;BR /&gt; sord=1&lt;BR /&gt; end;&lt;BR /&gt;if b then do;&lt;BR /&gt; ord=2;&lt;BR /&gt; sord=1&lt;BR /&gt; end; &lt;BR /&gt;if c then do;&lt;BR /&gt; ord=3;&lt;BR /&gt; sord=1&lt;BR /&gt; end;&lt;/P&gt;
&lt;P&gt;etc.....&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Assuming all the frequency tables originated from the same data perhaps you would be better served with a different procedure such as Proc Tabulate which will create a single table with frequencies of different variables:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=sashelp.class;
   class sex;
   class age;
   tables age sex,
          n='Count'
   ;
run;
          &lt;/PRE&gt;
&lt;P&gt;You can have the same variables involved in more that one place as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=sashelp.class;
   class sex;
   class age;
   tables age sex age*sex,
          n='Count'
          
   ;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Apr 2018 23:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-not-populating-variables-expected/m-p/453007#M114386</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-10T23:46:16Z</dc:date>
    </item>
  </channel>
</rss>

