<?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: Error message: sql, macro variables and datastep integration in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181973#M34702</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks very much &lt;A href="mailto:stat@sas...that"&gt;stat@sas...that&lt;/A&gt; was precisely what I was looking for...Didn't realize that the parenthesis are essential but it makes sense...macros are just text substitution so thx for your answer. It works!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 17 Jul 2014 22:09:18 GMT</pubDate>
    <dc:creator>Learn_uk</dc:creator>
    <dc:date>2014-07-17T22:09:18Z</dc:date>
    <item>
      <title>Error message: sql, macro variables and datastep integration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181969#M34698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, I have what appears to be an easy question but am getting an error. Perhaps you can help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is an example--I want to subset dataset x based on pt variable common only in dataset y. I want to do this using a macro variable (I realize there are many ways to do this but I just want to do it this way)...Can you help with the error?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;data x;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;input pt ht;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;datalines;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;1001 100&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;1002 32&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;1003 42&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;1004 93&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;data y;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;input pt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;datalines;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;1003&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;1003&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;1001&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct(pt) into :ids separated by ','&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from y;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;data x2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set x;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if pt in &amp;amp;ids then output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;I get an error message for the last datastep...Any ideas why?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Thanks very much for reading!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 00:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181969#M34698</guid>
      <dc:creator>Learn_uk</dc:creator>
      <dc:date>2014-07-17T00:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Error message: sql, macro variables and datastep integration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181970#M34699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just need to make a slight change in&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;data x2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set x;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if pt in &lt;STRONG&gt;(&amp;amp;ids)&lt;/STRONG&gt; then output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 01:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181970#M34699</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-07-17T01:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Error message: sql, macro variables and datastep integration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181971#M34700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just keep in mind that the maximum number of characters that can be stored in a Macro Variable is 65,534.&amp;nbsp; If you have a sizable dataset you may exceed this limitation and get an error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps you could use a join, a merge or another type of lookup to ensure you don't run into this issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is untested, so give it a shot and see how you go.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; CREATE TABLE Y1 AS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT X.PT, X.HT&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM X WHERE X.PT IN &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (SELECT DISTINCT(Y.PT) &lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM Y)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 04:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181971#M34700</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2014-07-17T04:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Error message: sql, macro variables and datastep integration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181972#M34701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A Hash Table might also be a valid solution.&amp;nbsp; The cool thing about the default functionality of the Hash Table is that it only contains unique values, so there is no need to dedupe or undertake a seperate SQL query to obtain the distinct values. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA HASHLOOKUP;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF _N_ = 1 THEN DO;&lt;/P&gt;&lt;P&gt;&amp;nbsp; DECLARE HASH HH(DATASET:'Y');&lt;/P&gt;&lt;P&gt;&amp;nbsp; HH.DEFINEKEY('PT');&lt;/P&gt;&lt;P&gt;&amp;nbsp; HH.DEFINEDONE();&lt;/P&gt;&lt;P&gt;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; DO UNTIL (DONE);&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET X END=DONE;&lt;/P&gt;&lt;P&gt;&amp;nbsp; RC = HH.CHECK();&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF RC = 0 THEN OUTPUT;&lt;/P&gt;&lt;P&gt;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RC = HH.CHECK();&amp;nbsp; checks to see if the key appears in the Hash Table and where it does it RC is populated with 0 (if not it is populated with a number other than 0).&amp;nbsp; If the values of RC is 0 then we output the values from the X dataset.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 04:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181972#M34701</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2014-07-17T04:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Error message: sql, macro variables and datastep integration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181973#M34702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks very much &lt;A href="mailto:stat@sas...that"&gt;stat@sas...that&lt;/A&gt; was precisely what I was looking for...Didn't realize that the parenthesis are essential but it makes sense...macros are just text substitution so thx for your answer. It works!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 22:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181973#M34702</guid>
      <dc:creator>Learn_uk</dc:creator>
      <dc:date>2014-07-17T22:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Error message: sql, macro variables and datastep integration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181974#M34703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Scott...I really appreciate your response! Thank you so much. I didn't know you could use SQL that way to do the subset (not requiring say an inner join)...very cool for teaching me a new technique.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 22:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181974#M34703</guid>
      <dc:creator>Learn_uk</dc:creator>
      <dc:date>2014-07-17T22:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error message: sql, macro variables and datastep integration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181975#M34704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Scott for the Hash Table method....Unfortunatly I don't know much about hashes so your code is outside my limited brain capacity...However, I shall learn to use hashes&amp;nbsp; &amp;amp; once I am comfortable enough shall revisit your solution in the future.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 22:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-message-sql-macro-variables-and-datastep-integration/m-p/181975#M34704</guid>
      <dc:creator>Learn_uk</dc:creator>
      <dc:date>2014-07-17T22:14:05Z</dc:date>
    </item>
  </channel>
</rss>

