<?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 Let Statement Inside Macro Not Assigning Value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Let-Statement-Inside-Macro-Not-Assigning-Value/m-p/856029#M338255</link>
    <description>&lt;P&gt;Hi all, I am attempting to assign a macro variable that is essentially a string of SQL code, but SAS is not assigning it for some reason. Here is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO DETERMINE_SOURCE_TABLE();
%IF &amp;amp;Inc_End. = &amp;amp;End_YYYY.0331 %THEN %DO;
	PROC SQL;
		CREATE TABLE WORK.Table2 AS	
			SELECT DISTINCT
				t1.CATEGORY,
				t1.PREFERENCE
				MIN(t1.EFF_DATE) AS MIN_OF_DATE
		FROM WORK.Table1 T1
			WHERE t1.DRUG_CATEGORY ~= '&amp;lt;NA&amp;gt;'
			GROUP BY 1,2,3,4,5,6,7,8,9,10,11;
	QUIT;


	/*GET RID OF LAST 3 MONTHS OF CLAIMS FROM PREVIOUS YEAR*/
	PROC SQL;
		CREATE TABLE WORK.Table3 AS	
		SELECT DISTINCT t1.*
		FROM  WORK.Table1 T1
		WHERE t1.EFF_DATE_SK GE &amp;amp;Inc_End_YYYY.0101;
	QUIT;


%LET Source = t2.MIN_OF_DATE AS MIN_OF_DATE
			  FROM WORK.Table3 t1 LEFT JOIN
				   WORK.Table2 t2 ON t1.CATEGORY = t2.CATEGORY AND
									t1.PREFERENCE = t2.PREFERENCE
			  WHERE t1.CATEGORY NE '&amp;lt;NA&amp;gt;'
			  GROUP BY 1,2;
%END;  	


%IF &amp;amp;Inc_End. &amp;gt; &amp;amp;End_YYYY.0331 %THEN %DO;
	%LET Source = MIN(t1.EFF_DATE_SK) AS MIN_OF_DATE
				  FROM WORK.Table1 t1
				  WHERE t1.CATEGORY NE '&amp;lt;NA&amp;gt;'
				  GROUP BY 1,2;
%END;

%MEND DETERMINE_SOURCE_TABLE;
%DETERMINE_SOURCE_TABLE
%PUT &amp;amp;Source;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see, when my first if Statement is true, I do some code, but when my second if&amp;nbsp;Statement is true, I just set the variable. For the code im running the first if statement is true but the variable is not setting correctly. Here is from the log&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MLOGIC(DETERMINE_SOURCE_TABLE):  Beginning execution.
88         %PUT &amp;amp;Source;
SYMBOLGEN:  Macro variable INC_END resolves to 20221231
SYMBOLGEN:  Macro variable END_YYYY resolves to 2022
MLOGIC(DETERMINE_SOURCE_TABLE):  %IF condition &amp;amp;Inc_End. = &amp;amp;End_YYYY.0331 is FALSE
SYMBOLGEN:  Macro variable INC_END resolves to 20221231
SYMBOLGEN:  Macro variable END_YYYY resolves to 2022
MLOGIC(DETERMINE_SOURCE_TABLE):  %IF condition &amp;amp;Inc_End. &amp;gt; &amp;amp;End_YYYY.0331 is TRUE
MLOGIC(DETERMINE_SOURCE_TABLE):  %LET (variable name is SOURCE)
MLOGIC(DETERMINE_SOURCE_TABLE):  Ending execution.
WARNING: Apparent symbolic reference SOURCE not resolved.
&amp;amp;Source&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any thoughts? Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jan 2023 17:45:05 GMT</pubDate>
    <dc:creator>mhoward2</dc:creator>
    <dc:date>2023-01-27T17:45:05Z</dc:date>
    <item>
      <title>Let Statement Inside Macro Not Assigning Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Let-Statement-Inside-Macro-Not-Assigning-Value/m-p/856029#M338255</link>
      <description>&lt;P&gt;Hi all, I am attempting to assign a macro variable that is essentially a string of SQL code, but SAS is not assigning it for some reason. Here is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO DETERMINE_SOURCE_TABLE();
%IF &amp;amp;Inc_End. = &amp;amp;End_YYYY.0331 %THEN %DO;
	PROC SQL;
		CREATE TABLE WORK.Table2 AS	
			SELECT DISTINCT
				t1.CATEGORY,
				t1.PREFERENCE
				MIN(t1.EFF_DATE) AS MIN_OF_DATE
		FROM WORK.Table1 T1
			WHERE t1.DRUG_CATEGORY ~= '&amp;lt;NA&amp;gt;'
			GROUP BY 1,2,3,4,5,6,7,8,9,10,11;
	QUIT;


	/*GET RID OF LAST 3 MONTHS OF CLAIMS FROM PREVIOUS YEAR*/
	PROC SQL;
		CREATE TABLE WORK.Table3 AS	
		SELECT DISTINCT t1.*
		FROM  WORK.Table1 T1
		WHERE t1.EFF_DATE_SK GE &amp;amp;Inc_End_YYYY.0101;
	QUIT;


%LET Source = t2.MIN_OF_DATE AS MIN_OF_DATE
			  FROM WORK.Table3 t1 LEFT JOIN
				   WORK.Table2 t2 ON t1.CATEGORY = t2.CATEGORY AND
									t1.PREFERENCE = t2.PREFERENCE
			  WHERE t1.CATEGORY NE '&amp;lt;NA&amp;gt;'
			  GROUP BY 1,2;
%END;  	


%IF &amp;amp;Inc_End. &amp;gt; &amp;amp;End_YYYY.0331 %THEN %DO;
	%LET Source = MIN(t1.EFF_DATE_SK) AS MIN_OF_DATE
				  FROM WORK.Table1 t1
				  WHERE t1.CATEGORY NE '&amp;lt;NA&amp;gt;'
				  GROUP BY 1,2;
%END;

%MEND DETERMINE_SOURCE_TABLE;
%DETERMINE_SOURCE_TABLE
%PUT &amp;amp;Source;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see, when my first if Statement is true, I do some code, but when my second if&amp;nbsp;Statement is true, I just set the variable. For the code im running the first if statement is true but the variable is not setting correctly. Here is from the log&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MLOGIC(DETERMINE_SOURCE_TABLE):  Beginning execution.
88         %PUT &amp;amp;Source;
SYMBOLGEN:  Macro variable INC_END resolves to 20221231
SYMBOLGEN:  Macro variable END_YYYY resolves to 2022
MLOGIC(DETERMINE_SOURCE_TABLE):  %IF condition &amp;amp;Inc_End. = &amp;amp;End_YYYY.0331 is FALSE
SYMBOLGEN:  Macro variable INC_END resolves to 20221231
SYMBOLGEN:  Macro variable END_YYYY resolves to 2022
MLOGIC(DETERMINE_SOURCE_TABLE):  %IF condition &amp;amp;Inc_End. &amp;gt; &amp;amp;End_YYYY.0331 is TRUE
MLOGIC(DETERMINE_SOURCE_TABLE):  %LET (variable name is SOURCE)
MLOGIC(DETERMINE_SOURCE_TABLE):  Ending execution.
WARNING: Apparent symbolic reference SOURCE not resolved.
&amp;amp;Source&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any thoughts? Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 17:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Let-Statement-Inside-Macro-Not-Assigning-Value/m-p/856029#M338255</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2023-01-27T17:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Let Statement Inside Macro Not Assigning Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Let-Statement-Inside-Macro-Not-Assigning-Value/m-p/856030#M338256</link>
      <description>&lt;P&gt;&amp;amp;source is defined and given a value in the macro, and it is not available outside the macro.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;To change this, you could insert this line into the macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global source;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 17:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Let-Statement-Inside-Macro-Not-Assigning-Value/m-p/856030#M338256</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-27T17:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Let Statement Inside Macro Not Assigning Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Let-Statement-Inside-Macro-Not-Assigning-Value/m-p/856033#M338257</link>
      <description>Just fade me fam.&lt;BR /&gt;&lt;BR /&gt;Thank you so much!! I was fully aboard the struggle bus.</description>
      <pubDate>Fri, 27 Jan 2023 17:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Let-Statement-Inside-Macro-Not-Assigning-Value/m-p/856033#M338257</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2023-01-27T17:50:53Z</dc:date>
    </item>
  </channel>
</rss>

