<?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 in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526309#M143307</link>
    <description>&lt;P&gt;%macro sq (var1=, var2=, var3=, var4=);&lt;BR /&gt;proc sql;&lt;BR /&gt;select count (distinct USUBJID) INTO:&amp;amp;var1 from ADAE where EYE="A" and &amp;amp;var4;&lt;BR /&gt;select count (distinct USUBJID) INTO:&amp;amp;var2 from ADAE where EYE="B" and &amp;amp;var4;&lt;BR /&gt;select count (distinct USUBJID) INTO:&amp;amp;var3 from ADAE where &amp;amp;var4;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;var1 &amp;amp;var2 &amp;amp;var3&lt;BR /&gt;%mend sq;&lt;/P&gt;&lt;P&gt;%sq( var1=x11, var2=x21, var3=x31, var4=%str(AETERM^=""));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;log is clear but program doesn't work .&lt;/P&gt;</description>
    <pubDate>Fri, 11 Jan 2019 09:19:17 GMT</pubDate>
    <dc:creator>Vahe_Mar</dc:creator>
    <dc:date>2019-01-11T09:19:17Z</dc:date>
    <item>
      <title>Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526309#M143307</link>
      <description>&lt;P&gt;%macro sq (var1=, var2=, var3=, var4=);&lt;BR /&gt;proc sql;&lt;BR /&gt;select count (distinct USUBJID) INTO:&amp;amp;var1 from ADAE where EYE="A" and &amp;amp;var4;&lt;BR /&gt;select count (distinct USUBJID) INTO:&amp;amp;var2 from ADAE where EYE="B" and &amp;amp;var4;&lt;BR /&gt;select count (distinct USUBJID) INTO:&amp;amp;var3 from ADAE where &amp;amp;var4;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;var1 &amp;amp;var2 &amp;amp;var3&lt;BR /&gt;%mend sq;&lt;/P&gt;&lt;P&gt;%sq( var1=x11, var2=x21, var3=x31, var4=%str(AETERM^=""));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;log is clear but program doesn't work .&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 09:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526309#M143307</guid>
      <dc:creator>Vahe_Mar</dc:creator>
      <dc:date>2019-01-11T09:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526317#M143310</link>
      <description>&lt;P&gt;Add&lt;/P&gt;
&lt;PRE&gt;options mprint mlogic symbolgen;&lt;/PRE&gt;
&lt;P&gt;before the macro is called, examine the log or post it here, but please post code and log using the {i} or running man icon to preserve formatting and increase readability. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could add&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put _local_;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as first command in an macro to write all parameters with their values to the log.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 10:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526317#M143310</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-01-11T10:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526325#M143312</link>
      <description>&lt;P&gt;Dear Andreas&amp;nbsp;&lt;/P&gt;&lt;P&gt;about readability will do next time thanks.&lt;/P&gt;&lt;P&gt;There are log like this.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SYMBOLGEN: Macro variable VAR1 resolves to x11&lt;BR /&gt;MLOGIC(SQ): %LET (variable name is x11)&lt;BR /&gt;SYMBOLGEN: Macro variable V1 resolves to 11&lt;BR /&gt;SYMBOLGEN: Macro variable VAR2 resolves to x21&lt;BR /&gt;MLOGIC(SQ): %LET (variable name is x21)&lt;BR /&gt;SYMBOLGEN: Macro variable V2 resolves to 5&lt;BR /&gt;SYMBOLGEN: Macro variable VAR3 resolves to x31&lt;BR /&gt;MLOGIC(SQ): %LET (variable name is x31)&lt;BR /&gt;SYMBOLGEN: Macro variable V3 resolves to 14&lt;BR /&gt;MLOGIC(SQ): %PUT _local_&lt;BR /&gt;SQ V1 11&lt;BR /&gt;SQ V2 5&lt;BR /&gt;SQ V3 14&lt;BR /&gt;SQ VAR1 x11&lt;BR /&gt;SQ VAR2 x21&lt;BR /&gt;SQ VAR3 x31&lt;BR /&gt;SQ VAR4 &amp;#1;AETERM&amp;#11;&amp;#28;""&amp;#2;&lt;BR /&gt;SQ X11 11&lt;BR /&gt;SQ X21 5&lt;BR /&gt;SQ X31 14&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but when I want to use like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp;x11 and get 11 its not working.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 11:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526325#M143312</guid>
      <dc:creator>Vahe_Mar</dc:creator>
      <dc:date>2019-01-11T11:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526326#M143313</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/100963"&gt;@Vahe_Mar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;log is clear but program doesn't work .&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What about it doesn't work? Show us the SASLOG. Show us the results you are getting and describe why they are wrong and what you expect.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 11:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526326#M143313</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-11T11:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526328#M143314</link>
      <description>"why they are wrong?" what you mean?</description>
      <pubDate>Fri, 11 Jan 2019 11:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526328#M143314</guid>
      <dc:creator>Vahe_Mar</dc:creator>
      <dc:date>2019-01-11T11:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526334#M143316</link>
      <description>&lt;P&gt;Hi Andreas_IDS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yout code works as intended, except for two problems with the&amp;nbsp;&lt;SPAN&gt;%put statement.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 1.&amp;nbsp; a missing semicolon in the %put statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 2. When you put&amp;nbsp;&amp;amp;var1, you get the&amp;nbsp;content of &amp;amp;var1, which is X31. You must use &amp;amp;&amp;amp;&amp;amp;var1 to resolve further and get the value of&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X31.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The noprint option on the proc sql statement is to prevent Proc SQL from generating&amp;nbsp;procedure output in the output window for the 3 selects.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data adae;
	USUBJID = 1; EYE = 'A'; AETERM = ''; output;
	USUBJID = 1; EYE = 'A'; AETERM = 'X'; output;
	USUBJID = 2; EYE = 'B'; AETERM = ''; output;
	USUBJID = 2; EYE = 'B'; AETERM = 'X'; output;
	USUBJID = 2; EYE = 'B'; AETERM = 'Y'; output;
run;

%macro sq (var1=, var2=, var3=, var4=);
	proc sql noprint;
		select count (distinct USUBJID) INTO:&amp;amp;var1 from ADAE where EYE="A" and &amp;amp;var4;
		select count (distinct USUBJID) INTO:&amp;amp;var2 from ADAE where EYE="B" and &amp;amp;var4;
		select count (distinct USUBJID) INTO:&amp;amp;var3 from ADAE where &amp;amp;var4;
	quit;

	%put &amp;amp;&amp;amp;&amp;amp;var1 &amp;amp;&amp;amp;&amp;amp;var2 &amp;amp;&amp;amp;&amp;amp;var3;
%mend sq;
%sq( var1=x11, var2=x21, var3=x31, var4=%str(AETERM^=""));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 1 2&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 12:05:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526334#M143316</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-01-11T12:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526335#M143317</link>
      <description>&lt;P&gt;Sorry Vahe_Mar&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I put a wong name in my post. But the code is for you, not Andreas_IDS.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 12:11:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526335#M143317</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-01-11T12:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526349#M143324</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/100963"&gt;@Vahe_Mar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;"why they are wrong?" what you mean?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am asking for a more detailed explanation. All you said was "doesn't work" and "not working" which tells us nothing.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 13:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526349#M143324</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-11T13:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526351#M143325</link>
      <description>after macro there are no issues, but when I want to use &amp;amp;x11 I have warning like " Apparent symbolic reference X11 not resolved" Actually I confused how to let &amp;amp;VAR1 ( X11) to var1 (macro derived in sql). And I want to use &amp;amp;X11 and have a value assigned in macro.</description>
      <pubDate>Fri, 11 Jan 2019 13:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526351#M143325</guid>
      <dc:creator>Vahe_Mar</dc:creator>
      <dc:date>2019-01-11T13:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526353#M143327</link>
      <description>&lt;P&gt;Show us the entire SAS log. Click on {i} and paste the SAS log into the window that appears.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 13:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526353#M143327</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-11T13:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526354#M143328</link>
      <description>WARNING: Apparent symbolic reference X11 not resolved.&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Jan 2019 13:30:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526354#M143328</guid>
      <dc:creator>Vahe_Mar</dc:creator>
      <dc:date>2019-01-11T13:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526355#M143329</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;MLOGIC(SQ): %PUT &amp;amp;&amp;amp;&amp;amp;var1 &amp;amp;&amp;amp;&amp;amp;var2 &amp;amp;&amp;amp;&amp;amp;var3&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable VAR1 resolves to x11&lt;BR /&gt;SYMBOLGEN: Macro variable X11 resolves to 11&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable VAR2 resolves to x21&lt;BR /&gt;SYMBOLGEN: Macro variable X21 resolves to 5&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable VAR3 resolves to x31&lt;BR /&gt;SYMBOLGEN: Macro variable X31 resolves to 14&lt;BR /&gt;11 5 14&lt;BR /&gt;MLOGIC(SQ): Ending execution.&lt;BR /&gt;WARNING: Apparent symbolic reference X31 not resolved.&lt;BR /&gt;4471 %put &amp;amp;x31;&lt;BR /&gt;&amp;amp;x31&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Jan 2019 13:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526355#M143329</guid>
      <dc:creator>Vahe_Mar</dc:creator>
      <dc:date>2019-01-11T13:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526358#M143331</link>
      <description>&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;PLEASE&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="4"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="4"&gt;&lt;FONT size="2"&gt;use these buttons &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="posting_code.jpg"&gt;&lt;img src="https://communities.sas.com/skins/images/8D8B612AA6AB1DC7E9A0812281D56E02/responsive_peak/images/image_not_found.png" alt="posting_code.jpg" /&gt;&lt;/span&gt; for posting logs and code, respectively.&lt;/FONT&gt;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 13:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526358#M143331</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-11T13:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526359#M143332</link>
      <description>&lt;P&gt;So, let's go back to message 2 of this thread, where&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;requested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Add&lt;/P&gt;
&lt;PRE&gt;options mprint mlogic symbolgen;&lt;/PRE&gt;
&lt;P&gt;before the macro is called, examine the log or post it here, but please post code and log using the {i} or running man icon to preserve formatting and increase readability.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please follow the instructions given by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;.&amp;nbsp;We're trying to help you, but you have to help us as well.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 13:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526359#M143332</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-11T13:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526361#M143333</link>
      <description>&lt;P&gt;Macro variables created by SQL are local, not global.&amp;nbsp; To make them global, add a line to your macro definition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro sq (var1=, var2=, var3=, var4=);&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;%global &amp;amp;var1 &amp;amp;var2 &amp;amp;var3;&lt;/FONT&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select count (distinct USUBJID) INTO:&amp;amp;var1 from ADAE where EYE="A" and &amp;amp;var4;&lt;BR /&gt;select count (distinct USUBJID) INTO:&amp;amp;var2 from ADAE where EYE="B" and &amp;amp;var4;&lt;BR /&gt;select count (distinct USUBJID) INTO:&amp;amp;var3 from ADAE where &amp;amp;var4;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;var1 &amp;amp;var2 &amp;amp;var3&lt;BR /&gt;%mend sq;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if &amp;amp;var4 gives you any &lt;FONT color="#000000"&gt;trouble&lt;/FONT&gt; (and it might), make the following additional change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;where&lt;/FONT&gt; %unquote(&lt;FONT color="#000000"&gt;&amp;amp;var4&lt;/FONT&gt;)&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 13:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-in-macro/m-p/526361#M143333</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-11T13:43:13Z</dc:date>
    </item>
  </channel>
</rss>

