<?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 Variable Query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Query/m-p/485037#M125976</link>
    <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;has said, that is a bad idea.&amp;nbsp; SAS is built around the concept of by group processing.&amp;nbsp; What you, and all these posts whereby lists are put into macro, then loops and multiple dataset, are doing is forcing it away from that core concept.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;produce the individual "Make" report&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can be re-written:&lt;BR /&gt;produce the report by make&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Which would look like:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;proc report data=sashelp.cars nowd;
  by make;
  title "#byval1";
  columns _all_;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;No need for different datasets, macro, or loops.&amp;nbsp; This core concept works in datastep and procedures.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Aug 2018 07:40:31 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-08-08T07:40:31Z</dc:date>
    <item>
      <title>Macro Variable Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Query/m-p/485006#M125955</link>
      <description>&lt;P&gt;May I know how to pass the "Make" data into the macro variable individually, and subsequently produce the individual "Make" report.&lt;/P&gt;&lt;P&gt;Below example have 4 different car models only, what if I have got 80 - 100 car brands? Anyone can help? Thanks.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test;&lt;BR /&gt;input brand $;&lt;BR /&gt;cards;&lt;BR /&gt;BMW&lt;BR /&gt;Audi&lt;BR /&gt;Honda&lt;BR /&gt;Toyota&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select distinct brand&lt;BR /&gt;into :brand separated by ''&lt;BR /&gt;from Test;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table &amp;amp;Brand as select distinct&lt;BR /&gt;* from sashelp.cars&lt;BR /&gt;where make eq "&amp;amp;Brand";&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 06:28:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Query/m-p/485006#M125955</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2018-08-08T06:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Query/m-p/485011#M125959</link>
      <description>&lt;P&gt;That's generally a bad idea.&amp;nbsp; Why not create 1 data set holding all 80 brands instead of keeping track of 80 data sets?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given that this is a training exercise to learn about macro language, the easiest way would be to use CALL EXECUTE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _null_;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;set test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;call execute('&lt;SPAN&gt;proc sql; create table ' || brand || &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;'as select distinct * from sashelp.cars where make eq "' || brand || '"; quit;');&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;If you are careful about it, you can reduce the code to a single PROC SQL instead of 80 PROC SQLs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _null_;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;call execute('proc sql;');&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;do until (done);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;set test end=done;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;call execute('&lt;SPAN&gt;create table ' || brand ||&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;'as select distinct * from sashelp.cars where make eq "' || brand || '";');&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;call execute('quit;');&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;stop;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 06:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Query/m-p/485011#M125959</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-08T06:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Query/m-p/485013#M125961</link>
      <description>&lt;P&gt;You can tweak your code and write a macro that does what you want. However, I much prefer to use the CALL EXECUTE Routine in this type of problem&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input brand $;
cards;
BMW
Audi
Honda
Toyota
;
run;

data callstack;
	set test;
	code=cats("data cars_",brand,"; set sashelp.cars(where=(Make='",brand,"'));run;");
	call execute(code);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Aug 2018 06:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Query/m-p/485013#M125961</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-08-08T06:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Query/m-p/485037#M125976</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;has said, that is a bad idea.&amp;nbsp; SAS is built around the concept of by group processing.&amp;nbsp; What you, and all these posts whereby lists are put into macro, then loops and multiple dataset, are doing is forcing it away from that core concept.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;produce the individual "Make" report&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can be re-written:&lt;BR /&gt;produce the report by make&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Which would look like:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;proc report data=sashelp.cars nowd;
  by make;
  title "#byval1";
  columns _all_;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;No need for different datasets, macro, or loops.&amp;nbsp; This core concept works in datastep and procedures.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 07:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Query/m-p/485037#M125976</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-08T07:40:31Z</dc:date>
    </item>
  </channel>
</rss>

