<?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: Why we can’t use where statement when we are reading data from external files? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715163#M220878</link>
    <description>&lt;P&gt;WHERE statement logic is outsourced to the data engine being used to read the data (and the data engine is specified in the LIBNAME statement).&amp;nbsp; If you can't specify a LIBNAME for the data, then there is no engine to perform the outsourced filtering.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you CAN use a subsetting IF statement, because it is not outsourced.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   input  x y code :$1.;
   if code='A';
datalines;
11 12 X
21 22 A
31 32 A
41 42 B
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 29 Jan 2021 03:19:48 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-01-29T03:19:48Z</dc:date>
    <item>
      <title>Why we can’t use where statement when we are reading data from external files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715048#M220828</link>
      <description>&lt;P&gt;Why we can’t use where statement when we are reading data from external files&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 16:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715048#M220828</guid>
      <dc:creator>Veera_48</dc:creator>
      <dc:date>2021-01-28T16:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why we can’t use where statement when we are reading data from external files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715049#M220829</link>
      <description>&lt;P&gt;In a data step WHERE refers to values from an incoming data set. From the documentation:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;P class="xis-shortDescription"&gt;Selects observations from SAS data sets that meet a particular condition.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since you are reading an external file then there are no 'observations from SAS data set' involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF will subset data for what is written to the output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If var in (&amp;lt;list of values goes here&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example would only write records where the IF is true to the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 16:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715049#M220829</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-28T16:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Why we can’t use where statement when we are reading data from external files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715057#M220834</link>
      <description>&lt;P&gt;Because the doc says so &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"You cannot use the WHERE statement to select records from an external file that contains raw data, nor can you use the WHERE statement within the same DATA step in which you read in-stream data with a DATALINES statement."&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 16:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715057#M220834</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-28T16:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Why we can’t use where statement when we are reading data from external files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715058#M220835</link>
      <description>&lt;P&gt;If you have permission to run operating system commands then read the output of a program that filters the source file instead of reading the file itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this code on Unix will only pass lines that contain the string YES to the data step to be read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'grep YES myfile.txt' pipe ;
  input ... ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jan 2021 16:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715058#M220835</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-28T16:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Why we can’t use where statement when we are reading data from external files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715070#M220841</link>
      <description>&lt;P&gt;There's an exception to the general rule: When reading certain types of external files you &lt;EM&gt;can&lt;/EM&gt; use a WHERE statement, provided that an appropriate &lt;EM&gt;engine&lt;/EM&gt; enables "dataset-like" access. For example, you can read (suitable) Excel files or MS Access tables in a DATA step with SET together with a WHERE statement via &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=acpcref&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SAS/ACCESS for PC Files&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly, with only Base SAS you can read &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=engxml&amp;amp;docsetTarget=n04ma5ck4gmc9mn1xa0crupbtiu5.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;XML files&lt;/A&gt;, which are plain text files with a specific structure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename myref 'C:\Temp\have.xml';

libname mylib xml xmlfileref=myref;

/* Create an XML file */

data mylib.have;
set sashelp.class(obs=3);
run;

/* Read selected records from the XML file */

data want;
set mylib.have;
where name like 'A%';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 22:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715070#M220841</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-01-28T22:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why we can’t use where statement when we are reading data from external files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715095#M220849</link>
      <description>Order of operations logic. The file is currently not a SAS data set so SAS doesn't know what's in it. To find out what's in it, it needs to process the file and read each line. When it reads the line of data and only NOW does it know that you don't want that line. So you can use an IF to drop it or conditionally not write it to the output. &lt;BR /&gt;&lt;BR /&gt;But WHERE filters data as it comes in to the system, because SAS already knows what exists in that data (or can easily find it out). The same is not true of a file that it doesn't 'know'.</description>
      <pubDate>Thu, 28 Jan 2021 19:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715095#M220849</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-01-28T19:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Why we can’t use where statement when we are reading data from external files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715098#M220850</link>
      <description>&lt;P&gt;If you want to use WHERE syntax while reading a text file or inline data, use the output dataset option:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test(where=(name contains "y"));
input name $;
datalines;
John
Mary
Henry
Lucy
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1611864493486.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54045iB8358F91CB47587B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1611864493486.png" alt="PGStats_0-1611864493486.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 20:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715098#M220850</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-01-28T20:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Why we can’t use where statement when we are reading data from external files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715159#M220877</link>
      <description>&lt;P&gt;You can use WHERE&amp;nbsp;statements when reading from a source referenced by a library name.&lt;/P&gt;
&lt;P&gt;So XML, excel, JSON, files can use a where clause. Similarly, Oracle or Teradata libraries also can.&lt;/P&gt;
&lt;P&gt;Though these are not SAS date sets, the engines make them appear as data sets to SAS programs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do not use a libname, you are reading a file which doesn't have defined variables yet.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since WHERE&amp;nbsp;clauses are processed &lt;STRONG&gt;before&lt;/STRONG&gt; the data is loaded by the step, and WHERE clauses use variable names, they can't be used.&lt;/P&gt;
&lt;P&gt;IF clauses can be used &lt;STRONG&gt;after&lt;/STRONG&gt; the variable names have been defined in the step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 02:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715159#M220877</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-01-29T02:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Why we can’t use where statement when we are reading data from external files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715163#M220878</link>
      <description>&lt;P&gt;WHERE statement logic is outsourced to the data engine being used to read the data (and the data engine is specified in the LIBNAME statement).&amp;nbsp; If you can't specify a LIBNAME for the data, then there is no engine to perform the outsourced filtering.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you CAN use a subsetting IF statement, because it is not outsourced.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   input  x y code :$1.;
   if code='A';
datalines;
11 12 X
21 22 A
31 32 A
41 42 B
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jan 2021 03:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-we-can-t-use-where-statement-when-we-are-reading-data-from/m-p/715163#M220878</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-29T03:19:48Z</dc:date>
    </item>
  </channel>
</rss>

