<?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 How to use csv as a list in WHERE statement? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807906#M318567</link>
    <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First off, my apologies if I do not include enough/the correct information - this is my first post on this site. Happy to receive feedback on how I can improve my "question asking".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have &amp;gt;1million subject IDs - each subject ID is 20 characters - in a CSV file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a proc sql block that pulls from a "master table", but I want to ONLY pull in the rows where the subject ID in the "master table" ALSO exists in the CSV file. It is a single column (see screenshot).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas_novice7_0-1649963534814.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70404iB1FE57C81BA5C194/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sas_novice7_0-1649963534814.png" alt="sas_novice7_0-1649963534814.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to use a WHERE statement in the proc sql block to accomplish this, but of course open to other methods.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried a few different methods, such as saving the entire csv as a ".mac" file and assigning it to a macro, but I got an error indicating the macro couldn't hold all the info I was trying to shove into it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have most recently tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc import 
	file = "blah blah file path"
	out = master_patid
	dbms = csv
	replace;
run;

proc sql;
	create table tablename as
	select a.subid, a.diag, b.subid, b.drg, b.fst_dt
	from source.&amp;amp;dataset. a left join source.&amp;amp;dataset. b
	on a.subid=b.subid
	&lt;STRONG&gt;where subid in (master_patid))&lt;/STRONG&gt;;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The error I get in my log file says "&lt;FONT color="#FF0000"&gt;Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My hunch is that it is not seeing the csv file as a list - but I haven't been able to figure out how to do so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate you taking the time to help me out!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Apr 2022 19:19:54 GMT</pubDate>
    <dc:creator>sas_novice7</dc:creator>
    <dc:date>2022-04-14T19:19:54Z</dc:date>
    <item>
      <title>How to use csv as a list in WHERE statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807906#M318567</link>
      <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First off, my apologies if I do not include enough/the correct information - this is my first post on this site. Happy to receive feedback on how I can improve my "question asking".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have &amp;gt;1million subject IDs - each subject ID is 20 characters - in a CSV file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a proc sql block that pulls from a "master table", but I want to ONLY pull in the rows where the subject ID in the "master table" ALSO exists in the CSV file. It is a single column (see screenshot).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas_novice7_0-1649963534814.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70404iB1FE57C81BA5C194/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sas_novice7_0-1649963534814.png" alt="sas_novice7_0-1649963534814.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to use a WHERE statement in the proc sql block to accomplish this, but of course open to other methods.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried a few different methods, such as saving the entire csv as a ".mac" file and assigning it to a macro, but I got an error indicating the macro couldn't hold all the info I was trying to shove into it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have most recently tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc import 
	file = "blah blah file path"
	out = master_patid
	dbms = csv
	replace;
run;

proc sql;
	create table tablename as
	select a.subid, a.diag, b.subid, b.drg, b.fst_dt
	from source.&amp;amp;dataset. a left join source.&amp;amp;dataset. b
	on a.subid=b.subid
	&lt;STRONG&gt;where subid in (master_patid))&lt;/STRONG&gt;;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The error I get in my log file says "&lt;FONT color="#FF0000"&gt;Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My hunch is that it is not seeing the csv file as a list - but I haven't been able to figure out how to do so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate you taking the time to help me out!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 19:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807906#M318567</guid>
      <dc:creator>sas_novice7</dc:creator>
      <dc:date>2022-04-14T19:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use csv as a list in WHERE statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807915#M318573</link>
      <description>&lt;P&gt;First of all, you have one opening bracket, but two closing brackets.&lt;/P&gt;
&lt;P&gt;Second, use a sub-select:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where subid in (select concat from master_patid)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Apr 2022 19:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807915#M318573</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-14T19:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to use csv as a list in WHERE statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807916#M318574</link>
      <description>&lt;P&gt;Please show us the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log for this PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the future, whenever you have errors in the log, we need to see the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log for the step (PROC or DATA step) that has the errors. Do not show us errors detached from the code as it appears in the log. Do not show us parts of the log of this step and chop out other parts of the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please copy the log as text and paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66123iA4EF494F9CA0F6EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" alt="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 20:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807916#M318574</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-14T20:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to use csv as a list in WHERE statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807938#M318578</link>
      <description>&lt;P&gt;No need for PROC IMPROT to read a simple text file, especially one with only one variable. Use FIRSTOBS=2 to skip the extra line at the top in your photograph of the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master_pid;
  infile "blah blah file path" dsd firstobs=2 truncover;
  input patid :$20. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Are the quotes actually in the file?&amp;nbsp; Should the quotes actually be part of the values to be found?&amp;nbsp; If not then using the DSD option on INFILE statement will remove the quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the issue just to subset some existing dataset?&amp;nbsp; So if there is an existing dataset named HAVE that also has a variable named PATID the you want to subset then just do an INNER JOIN to find the observations that are in both.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
  select a.* 
  from HAVE a
  inner join MASTER_PID b
  on a.patid = b.patid
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Apr 2022 21:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807938#M318578</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-14T21:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use csv as a list in WHERE statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807943#M318581</link>
      <description>Very helpful - really appreciate you taking the time - issue has been resolved for now, but I learned a lot from your response.</description>
      <pubDate>Thu, 14 Apr 2022 23:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-csv-as-a-list-in-WHERE-statement/m-p/807943#M318581</guid>
      <dc:creator>sas_novice7</dc:creator>
      <dc:date>2022-04-14T23:52:56Z</dc:date>
    </item>
  </channel>
</rss>

