<?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: Using Macro Variables in Proc Sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569477#M160491</link>
    <description>&lt;P&gt;Now I have a data set where the variable I'm interested in is populated with values that are variations on the 'LYMPOST_DS_LYM_DIS_STAT_BY_CT' variable such as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'LYMPOST_DS_LYM_DIS_STAT_BY_CT'&amp;nbsp;&lt;/P&gt;&lt;P&gt;'LYMPOST_DS_LYM_DIS_STAT_BY_CT_6M'&lt;/P&gt;&lt;P&gt;'LYMPOST_DS_LYM_DIS_STAT_BY_CT_ALL_HIGH'&lt;/P&gt;&lt;P&gt;'LYMPOST_DS_LYM_DIS_STAT_BY_CT_ONE_LOW'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to delete some rows specific to the variation on the name using code like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
DELETE FROM SINGLE_VAR t1
 	WHERE t1.KEY = 'LYMPOST_DS_LYM_DIS_STAT_BY_CT';

DELETE FROM SINGLE_VAR t1
 	WHERE t1.KEY LIKE 'LYMPOST_DS_LYM_DIS_STAT_BY_CT_ONE%';

DELETE FROM SINGLE_VAR t1
 	WHERE t1.KEY LIKE 'LYMPOST_DS_LYM_DIS_STAT_BY_CT_ALL%';

QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However now I would like to use macros. I cannot simply use "&amp;amp;varname1" because I would like to keep the&amp;nbsp;'LYMPOST_DS_LYM_DIS_STAT_BY_CT_6M' value and others like it.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jun 2019 15:04:53 GMT</pubDate>
    <dc:creator>bignate1030</dc:creator>
    <dc:date>2019-06-27T15:04:53Z</dc:date>
    <item>
      <title>Using Macro Variables in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569460#M160481</link>
      <description>&lt;P&gt;Currently I have this code:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE LYMPOST_A AS 
	SELECT * FROM WORK.KVS_EVENT_DATA t1
		WHERE t1.KEY LIKE 'LYMPOST_DS_LYM_DIS_STAT_BY_CT%'
		ORDER BY PERSON_ID, MAIN_EVENT_ID, EVENT_ID;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to replace the variable name in the LIKE statement with a macro variable, something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET VARNAME1 = LYMPOST_DS_LYM_DIS_STAT_BY_CT;

PROC SQL;
CREATE TABLE LYMPOST_A AS 
	SELECT * FROM WORK.KVS_EVENT_DATA t1
		WHERE t1.KEY LIKE 'VARNAME1%'
		ORDER BY PERSON_ID, MAIN_EVENT_ID, EVENT_ID;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This code creates a table but does not populate it. Any help is appreciated&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 14:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569460#M160481</guid>
      <dc:creator>bignate1030</dc:creator>
      <dc:date>2019-06-27T14:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro Variables in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569464#M160483</link>
      <description>&lt;P&gt;Use an &lt;STRONG&gt;&amp;amp;&amp;nbsp;&lt;/STRONG&gt;to refer to the macro variable and put it in double quotation marks to resolve the macro variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET VARNAME1 = LYMPOST_DS_LYM_DIS_STAT_BY_CT;

PROC SQL;
CREATE TABLE LYMPOST_A AS 
	SELECT * FROM WORK.KVS_EVENT_DATA t1
		WHERE t1.KEY LIKE "&amp;amp;VARNAME1.%"
		ORDER BY PERSON_ID, MAIN_EVENT_ID, EVENT_ID;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jun 2019 14:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569464#M160483</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-27T14:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro Variables in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569477#M160491</link>
      <description>&lt;P&gt;Now I have a data set where the variable I'm interested in is populated with values that are variations on the 'LYMPOST_DS_LYM_DIS_STAT_BY_CT' variable such as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'LYMPOST_DS_LYM_DIS_STAT_BY_CT'&amp;nbsp;&lt;/P&gt;&lt;P&gt;'LYMPOST_DS_LYM_DIS_STAT_BY_CT_6M'&lt;/P&gt;&lt;P&gt;'LYMPOST_DS_LYM_DIS_STAT_BY_CT_ALL_HIGH'&lt;/P&gt;&lt;P&gt;'LYMPOST_DS_LYM_DIS_STAT_BY_CT_ONE_LOW'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to delete some rows specific to the variation on the name using code like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
DELETE FROM SINGLE_VAR t1
 	WHERE t1.KEY = 'LYMPOST_DS_LYM_DIS_STAT_BY_CT';

DELETE FROM SINGLE_VAR t1
 	WHERE t1.KEY LIKE 'LYMPOST_DS_LYM_DIS_STAT_BY_CT_ONE%';

DELETE FROM SINGLE_VAR t1
 	WHERE t1.KEY LIKE 'LYMPOST_DS_LYM_DIS_STAT_BY_CT_ALL%';

QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However now I would like to use macros. I cannot simply use "&amp;amp;varname1" because I would like to keep the&amp;nbsp;'LYMPOST_DS_LYM_DIS_STAT_BY_CT_6M' value and others like it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 15:04:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569477#M160491</guid>
      <dc:creator>bignate1030</dc:creator>
      <dc:date>2019-06-27T15:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro Variables in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569481#M160492</link>
      <description>&lt;P&gt;Use the same method.&lt;/P&gt;
&lt;P&gt;Please show what you tried and explain how it didn't work.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 15:08:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569481#M160492</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-27T15:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro Variables in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569493#M160495</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
DELETE FROM SINGLE_VAR t1
 	WHERE t1.KEY = "&amp;amp;VARNAME1";
DELETE FROM SINGLE_VAR t1
 	WHERE t1.KEY LIKE "&amp;amp;VARNAME1_ONE%";
DELETE FROM SINGLE_VAR t1
 	WHERE t1.KEY LIKE "&amp;amp;VARNAME1_ALL%";
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is what I tried and it throws the warning "Apparent symbolic reference VARNAME1_ONE not resolved" (Same for VARNAME1_ALL).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 15:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569493#M160495</guid>
      <dc:creator>bignate1030</dc:creator>
      <dc:date>2019-06-27T15:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro Variables in Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569498#M160496</link>
      <description>&lt;P&gt;To prevent that you need to add a period after the end of the macro variable name.&amp;nbsp; Otherwise the macro processor will keep using any character that can validly be used in a name as part of the variable name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE t1.KEY LIKE "&amp;amp;VARNAME1._ONE%";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note this means that if you want to insert an actual period after the value of the macro variable then you need to type two of them since the first one will be used by the macro processor as part of the macro variable reference.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 15:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-in-Proc-Sql/m-p/569498#M160496</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-27T15:36:23Z</dc:date>
    </item>
  </channel>
</rss>

