<?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 Proc SQL inside macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-inside-macro/m-p/142509#M261686</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following two datasets:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt;data big&lt;/STRONG&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input Obs ID &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;V1&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;datalines;&lt;/P&gt;&lt;P&gt; 1 1 1 &lt;/P&gt;&lt;P&gt; 2 2 1 &lt;/P&gt;&lt;P&gt; 3 2 2 &lt;/P&gt;&lt;P&gt; 4 3 1 &lt;/P&gt;&lt;P&gt; 5 3 2 &lt;/P&gt;&lt;P&gt; 6 3 3 &lt;/P&gt;&lt;P&gt; 7 4 1 &lt;/P&gt;&lt;P&gt; 8 4 2 &lt;/P&gt;&lt;P&gt; 9 4 3&lt;/P&gt;&lt;P&gt;10 5 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt;data small&lt;/STRONG&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input Obs ID&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;datalines;&lt;/P&gt;&lt;P&gt; 1 2 &lt;/P&gt;&lt;P&gt; 2 4&lt;/P&gt;&lt;P&gt; 3 5;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to obtain the dataset WANT, which contains all variables in the dataset BIG and all observations in dataset BIG with a value of the variable ID that occurs in the dataset SMALL. That is, I would like to obtain the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt;data want&lt;/STRONG&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input Obs ID &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;V1&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;datalines;&lt;/P&gt;&lt;P&gt; 1 2 1 &lt;/P&gt;&lt;P&gt; 2 2 2 &lt;/P&gt;&lt;P&gt; 3 4 1 &lt;/P&gt;&lt;P&gt; 4 4 2 &lt;/P&gt;&lt;P&gt; 5 4 3&lt;/P&gt;&lt;P&gt; 6 5 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have managed to do it by using PROC SQL. This is my attempt:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; create table want as &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; select big.* &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; from big, small &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; where big.id = small.id; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I also need to create a macro because I have many datasets BIG. Here, I have problems with syntax of PROC SQL inside a macro. The following code doesn't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro sampling(big);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; create table want as &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; select &amp;amp;big.* &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; from &amp;amp;big., small&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; where &amp;amp;big.dt = small.dt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc append base=final data=want;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc delete data=want;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Any help would be highly appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Sep 2014 14:25:14 GMT</pubDate>
    <dc:creator>mark_ph</dc:creator>
    <dc:date>2014-09-12T14:25:14Z</dc:date>
    <item>
      <title>Proc SQL inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-inside-macro/m-p/142509#M261686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following two datasets:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt;data big&lt;/STRONG&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input Obs ID &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;V1&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;datalines;&lt;/P&gt;&lt;P&gt; 1 1 1 &lt;/P&gt;&lt;P&gt; 2 2 1 &lt;/P&gt;&lt;P&gt; 3 2 2 &lt;/P&gt;&lt;P&gt; 4 3 1 &lt;/P&gt;&lt;P&gt; 5 3 2 &lt;/P&gt;&lt;P&gt; 6 3 3 &lt;/P&gt;&lt;P&gt; 7 4 1 &lt;/P&gt;&lt;P&gt; 8 4 2 &lt;/P&gt;&lt;P&gt; 9 4 3&lt;/P&gt;&lt;P&gt;10 5 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt;data small&lt;/STRONG&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input Obs ID&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;datalines;&lt;/P&gt;&lt;P&gt; 1 2 &lt;/P&gt;&lt;P&gt; 2 4&lt;/P&gt;&lt;P&gt; 3 5;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to obtain the dataset WANT, which contains all variables in the dataset BIG and all observations in dataset BIG with a value of the variable ID that occurs in the dataset SMALL. That is, I would like to obtain the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt;data want&lt;/STRONG&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;input Obs ID &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;V1&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;datalines;&lt;/P&gt;&lt;P&gt; 1 2 1 &lt;/P&gt;&lt;P&gt; 2 2 2 &lt;/P&gt;&lt;P&gt; 3 4 1 &lt;/P&gt;&lt;P&gt; 4 4 2 &lt;/P&gt;&lt;P&gt; 5 4 3&lt;/P&gt;&lt;P&gt; 6 5 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have managed to do it by using PROC SQL. This is my attempt:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; create table want as &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; select big.* &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; from big, small &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; where big.id = small.id; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I also need to create a macro because I have many datasets BIG. Here, I have problems with syntax of PROC SQL inside a macro. The following code doesn't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro sampling(big);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; create table want as &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; select &amp;amp;big.* &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; from &amp;amp;big., small&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; where &amp;amp;big.dt = small.dt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc append base=final data=want;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc delete data=want;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Any help would be highly appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2014 14:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-inside-macro/m-p/142509#M261686</guid>
      <dc:creator>mark_ph</dc:creator>
      <dc:date>2014-09-12T14:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-inside-macro/m-p/142510#M261687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you have to address the variables from the table like this &amp;amp;big&lt;SPAN style="font-size: 14pt;"&gt;&lt;STRONG&gt;..&lt;/STRONG&gt;&lt;/SPAN&gt;* therefore you should corect these lines :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select &amp;amp;big..* --&amp;gt; &amp;amp;big&lt;SPAN style="font-size: 14pt;"&gt;&lt;STRONG&gt;..&lt;/STRONG&gt;&lt;/SPAN&gt;*&lt;/P&gt;&lt;P&gt;&amp;amp;big.dt --&amp;gt; &amp;amp;big&lt;SPAN style="font-size: 14pt;"&gt;..&lt;/SPAN&gt;dt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2014 14:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-inside-macro/m-p/142510#M261687</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-09-12T14:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-inside-macro/m-p/142511#M261688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I read your description correctly you want a join not a Cartesian product&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; select &amp;amp;big.*, small.id &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; from &amp;amp;big. left join small&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; on &amp;amp;big..dt = small.dt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2014 14:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-inside-macro/m-p/142511#M261688</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-09-12T14:45:35Z</dc:date>
    </item>
  </channel>
</rss>

