<?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: Reading a Macro list in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835321#M330238</link>
    <description>Your macro variable already contains brackets, so you do not need&lt;BR /&gt;additional ones when you call it.</description>
    <pubDate>Mon, 26 Sep 2022 21:14:21 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-09-26T21:14:21Z</dc:date>
    <item>
      <title>Reading a Macro list in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835317#M330235</link>
      <description>&lt;P&gt;I want to read these two macro into the proc sql. I keep getting an error that a select statement is missing; I put a smaple dataset at the below to use&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%LET ZIPCODE_LIST2=('95201','95202','95203','95204','95205','95206','95207','95208','95209','95210','95211','95212','95213','95214','95215','95219',&lt;BR /&gt;'95267','95269','95296','95297');&lt;/P&gt;&lt;P&gt;%let yrmo_b2=202208;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;CREATE TABLE attrib2 AS&lt;BR /&gt;seLECT *,&lt;BR /&gt;case index&lt;BR /&gt;when '211A' then '212A'&lt;BR /&gt;when '211B' then '212B'&lt;BR /&gt;when '211C' then '212C'&lt;BR /&gt;when '211D' then '212D'&lt;BR /&gt;when '211E' then '212E'&lt;BR /&gt;else index2 end&lt;BR /&gt;FROM attrib1&lt;BR /&gt;WHERE zipcode IN (&amp;amp;ZIPCODE_LIST2)&lt;BR /&gt;and yrmo&amp;nbsp; in ( 202207 ,&amp;amp;yrmo_b2);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA ACO1;&lt;BR /&gt;input ID $ INDEX $ YRMO zipcode $;&lt;BR /&gt;DATALINES;&lt;BR /&gt;10528076 211D 202207 95204&lt;BR /&gt;10588202 211E 202207 95212&lt;BR /&gt;10590191 211B 201802 95336&lt;BR /&gt;10593162 211D 202208 95219&lt;BR /&gt;10593777 211D 202204 95201&lt;BR /&gt;10593787 211D 201802 95336&lt;BR /&gt;10594270 211C 201802 95376&lt;BR /&gt;10594273 211C 202208 95214&lt;BR /&gt;10595143 211D 201802 95336&lt;BR /&gt;10596446 211E 202208 95336&lt;BR /&gt;10597124 211D 202207 95201&lt;BR /&gt;10597867 211D 202206 95376&lt;BR /&gt;10598211 211A 202201 95249&lt;BR /&gt;10600934 211D 201802 95202&lt;BR /&gt;10600935 211D 202205 95336&lt;BR /&gt;10601192 211D 202205 95213&lt;BR /&gt;10689802 211A 201802 95204&lt;BR /&gt;10702706 211C 202208 95204&lt;BR /&gt;10735256 211E 202207 95201&lt;BR /&gt;10750858 211D 202208 95210&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 21:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835317#M330235</guid>
      <dc:creator>grnize</dc:creator>
      <dc:date>2022-09-26T21:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a Macro list in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835320#M330237</link>
      <description>&lt;P&gt;Your list has parentheses in it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET ZIPCODE_LIST2=('95201','95202','95203','95204','95205','95206','95207','95208','95209','95210','95211','95212','95213','95214','95215','95219',
'95267','95269','95296','95297');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your where clause also has parentheses:&lt;/P&gt;
&lt;PRE&gt;WHERE zipcode IN (&amp;amp;ZIPCODE_LIST2)&lt;/PRE&gt;
&lt;P&gt;This results in too many parentheses. I would remove the parentheses from your list, i.e. change to:&lt;/P&gt;
&lt;PRE&gt;%LET ZIPCODE_LIST2='95201','95202','95203','95204','95205','95206','95207','95208','95209','95210','95211','95212','95213','95214','95215','95219',
'95267','95269','95296','95297';&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 21:13:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835320#M330237</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-09-26T21:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a Macro list in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835321#M330238</link>
      <description>Your macro variable already contains brackets, so you do not need&lt;BR /&gt;additional ones when you call it.</description>
      <pubDate>Mon, 26 Sep 2022 21:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835321#M330238</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-26T21:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a Macro list in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835324#M330241</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The CASE statement is missing a new name assigned&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Extra parenthesis on the zipcode_list2 macro variable&lt;/LI&gt;
&lt;LI&gt;Missing semicolon on the data step to create your sample data&lt;/LI&gt;
&lt;LI&gt;Assumes ACO1 is the sample input data set (not the same name as in the code)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA ATTRIB1;
input ID $ INDEX $ YRMO zipcode $;
DATALINES;
10528076 211D 202207 95204
10588202 211E 202207 95212
10590191 211B 201802 95336
10593162 211D 202208 95219
10593777 211D 202204 95201
10593787 211D 201802 95336
10594270 211C 201802 95376
10594273 211C 202208 95214
10595143 211D 201802 95336
10596446 211E 202208 95336
10597124 211D 202207 95201
10597867 211D 202206 95376
10598211 211A 202201 95249
10600934 211D 201802 95202
10600935 211D 202205 95336
10601192 211D 202205 95213
10689802 211A 201802 95204
10702706 211C 202208 95204
10735256 211E 202207 95201
10750858 211D 202208 95210
;;;; /*add semicolon to have sample data read in correctly*/
RUN;


%LET ZIPCODE_LIST2=('95201','95202','95203','95204','95205','95206','95207','95208','95209','95210','95211','95212','95213','95214','95215','95219',
'95267','95269','95296','95297');

%let yrmo_b2=202208;

 

proc sql;
CREATE TABLE attrib2 AS
seLECT *,
case index
when '211A' then '212A'
when '211B' then '212B'
when '211C' then '212C'
when '211D' then '212D'
when '211E' then '212E'
else '' end as index2  /*end the case statement properly*/
FROM attrib1
WHERE zipcode IN &amp;amp;ZIPCODE_LIST2 /*remove parenthesis from code*/
and yrmo  in (202207, &amp;amp;yrmo_b2);

quit;

 


 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434892"&gt;@grnize&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to read these two macro into the proc sql. I keep getting an error that a select statement is missing; I put a smaple dataset at the below to use&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%LET ZIPCODE_LIST2=('95201','95202','95203','95204','95205','95206','95207','95208','95209','95210','95211','95212','95213','95214','95215','95219',&lt;BR /&gt;'95267','95269','95296','95297');&lt;/P&gt;
&lt;P&gt;%let yrmo_b2=202208;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;CREATE TABLE attrib2 AS&lt;BR /&gt;seLECT *,&lt;BR /&gt;case index&lt;BR /&gt;when '211A' then '212A'&lt;BR /&gt;when '211B' then '212B'&lt;BR /&gt;when '211C' then '212C'&lt;BR /&gt;when '211D' then '212D'&lt;BR /&gt;when '211E' then '212E'&lt;BR /&gt;else index2 end&lt;BR /&gt;FROM attrib1&lt;BR /&gt;WHERE zipcode IN (&amp;amp;ZIPCODE_LIST2)&lt;BR /&gt;and yrmo&amp;nbsp; in ( 202207 ,&amp;amp;yrmo_b2);&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA ACO1;&lt;BR /&gt;input ID $ INDEX $ YRMO zipcode $;&lt;BR /&gt;DATALINES;&lt;BR /&gt;10528076 211D 202207 95204&lt;BR /&gt;10588202 211E 202207 95212&lt;BR /&gt;10590191 211B 201802 95336&lt;BR /&gt;10593162 211D 202208 95219&lt;BR /&gt;10593777 211D 202204 95201&lt;BR /&gt;10593787 211D 201802 95336&lt;BR /&gt;10594270 211C 201802 95376&lt;BR /&gt;10594273 211C 202208 95214&lt;BR /&gt;10595143 211D 201802 95336&lt;BR /&gt;10596446 211E 202208 95336&lt;BR /&gt;10597124 211D 202207 95201&lt;BR /&gt;10597867 211D 202206 95376&lt;BR /&gt;10598211 211A 202201 95249&lt;BR /&gt;10600934 211D 201802 95202&lt;BR /&gt;10600935 211D 202205 95336&lt;BR /&gt;10601192 211D 202205 95213&lt;BR /&gt;10689802 211A 201802 95204&lt;BR /&gt;10702706 211C 202208 95204&lt;BR /&gt;10735256 211E 202207 95201&lt;BR /&gt;10750858 211D 202208 95210&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 21:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835324#M330241</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-26T21:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a Macro list in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835331#M330246</link>
      <description>I’m stilling getting error of missing )&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Sep 2022 22:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835331#M330246</guid>
      <dc:creator>grnize</dc:creator>
      <dc:date>2022-09-26T22:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a Macro list in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835341#M330255</link>
      <description>&lt;P&gt;You need to post your code and log if you're still getting errors.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the code I posted was tested and ran without issues.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 22:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-Macro-list-in-proc-sql/m-p/835341#M330255</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-26T22:45:17Z</dc:date>
    </item>
  </channel>
</rss>

