<?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 Import rows of csv file except those satisfying conditions plus the previous/following ones in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/337876#M272566</link>
    <description>&lt;P&gt;I would like to import all the rows of a csv file, except the&amp;nbsp;rows satisfyng some conditions together with the previous and/or following rows. For example, in the following example I would like to import all rows, except those&amp;nbsp;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;in which var1 = paris, and the previous row.&lt;/P&gt;&lt;P&gt;- in which var1 = madrid, and both the previous and the following row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 
 &lt;SPAN class="token statement"&gt;infile&lt;/SPAN&gt; datalines&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; 
   var1 &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;
   var2
   var3&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 datalines&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 abc &lt;SPAN class="token number"&gt;73&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;985&lt;/SPAN&gt;
 abc &lt;SPAN class="token number"&gt;132&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;163&lt;/SPAN&gt;
 paris &lt;SPAN class="token number"&gt;220&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;193&lt;/SPAN&gt; &lt;BR /&gt; gft &lt;SPAN class="token number"&gt;685&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;741&lt;/SPAN&gt;
 cde &lt;SPAN class="token number"&gt;195&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;163&lt;/SPAN&gt;
 paris &lt;SPAN class="token number"&gt;220&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;198&lt;/SPAN&gt;
 cde &lt;SPAN class="token number"&gt;173&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;155&lt;/SPAN&gt;
 abe &lt;SPAN class="token number"&gt;135&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;116&lt;/SPAN&gt;
 madrid &lt;SPAN class="token number"&gt;735&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;161&lt;/SPAN&gt; 
 " &lt;SPAN class="token number"&gt;173&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;155&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It follows that the dataset want only contains the observations "abc 73 985" and "gft 685 741".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
    <pubDate>Mon, 06 Mar 2017 07:28:35 GMT</pubDate>
    <dc:creator>user_</dc:creator>
    <dc:date>2017-03-06T07:28:35Z</dc:date>
    <item>
      <title>Import rows of csv file except those satisfying conditions plus the previous/following ones</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/337876#M272566</link>
      <description>&lt;P&gt;I would like to import all the rows of a csv file, except the&amp;nbsp;rows satisfyng some conditions together with the previous and/or following rows. For example, in the following example I would like to import all rows, except those&amp;nbsp;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;in which var1 = paris, and the previous row.&lt;/P&gt;&lt;P&gt;- in which var1 = madrid, and both the previous and the following row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 
 &lt;SPAN class="token statement"&gt;infile&lt;/SPAN&gt; datalines&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; 
   var1 &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;
   var2
   var3&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 datalines&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 abc &lt;SPAN class="token number"&gt;73&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;985&lt;/SPAN&gt;
 abc &lt;SPAN class="token number"&gt;132&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;163&lt;/SPAN&gt;
 paris &lt;SPAN class="token number"&gt;220&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;193&lt;/SPAN&gt; &lt;BR /&gt; gft &lt;SPAN class="token number"&gt;685&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;741&lt;/SPAN&gt;
 cde &lt;SPAN class="token number"&gt;195&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;163&lt;/SPAN&gt;
 paris &lt;SPAN class="token number"&gt;220&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;198&lt;/SPAN&gt;
 cde &lt;SPAN class="token number"&gt;173&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;155&lt;/SPAN&gt;
 abe &lt;SPAN class="token number"&gt;135&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;116&lt;/SPAN&gt;
 madrid &lt;SPAN class="token number"&gt;735&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;161&lt;/SPAN&gt; 
 " &lt;SPAN class="token number"&gt;173&lt;/SPAN&gt;  &lt;SPAN class="token number"&gt;155&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It follows that the dataset want only contains the observations "abc 73 985" and "gft 685 741".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 07:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/337876#M272566</guid>
      <dc:creator>user_</dc:creator>
      <dc:date>2017-03-06T07:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Import rows of csv file except those satisfying conditions plus the previous/following ones</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/337924#M272567</link>
      <description>&lt;P&gt;Are you opposed to importing first and then doing the subsetting?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 17:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/337924#M272567</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-03-03T17:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Import rows of csv file except those satisfying conditions plus the previous/following ones</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/337930#M272568</link>
      <description>&lt;P&gt;As shown the "gft 685 741" can't match your requirement as it is on the same row as 'paris'.&lt;/P&gt;
&lt;P&gt;Please correct you datalines section.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if the " is supposed to represent a blank/missing value that is incorrect. Use&amp;nbsp;a single period&amp;nbsp;instead. The double quote becomes the value of a variable as does two single quotes.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 17:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/337930#M272568</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-03T17:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Import rows of csv file except those satisfying conditions plus the previous/following ones</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/338364#M272569</link>
      <description>&lt;P&gt;Thank you for spotting that. For some reason I cannot write it in the correct way as a&amp;nbsp;SAS code. But yes,&amp;nbsp;it should be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token statement"&gt;infile&lt;/SPAN&gt; datalines&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; var1 &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; var2 var3&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;datalines&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;abc &lt;SPAN class="token number"&gt;73&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;985&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;abc &lt;SPAN class="token number"&gt;132&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;163&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;paris &lt;SPAN class="token number"&gt;220&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;193&lt;/SPAN&gt;&lt;BR /&gt;gft &lt;SPAN class="token number"&gt;685&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;741&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;cde &lt;SPAN class="token number"&gt;195&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;163&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;paris &lt;SPAN class="token number"&gt;220&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;198&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;cde &lt;SPAN class="token number"&gt;173&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;155&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;abe &lt;SPAN class="token number"&gt;135&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;116&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;madrid &lt;SPAN class="token number"&gt;735&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;161&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;" &lt;SPAN class="token number"&gt;173&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;155&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;The "&amp;nbsp;could be the value of a variable,&amp;nbsp;but if creates confusion I could replace it with anything else.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;On the other hand, there could also be blank\missing values.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 07:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/338364#M272569</guid>
      <dc:creator>user_</dc:creator>
      <dc:date>2017-03-06T07:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Import rows of csv file except those satisfying conditions plus the previous/following ones</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/338366#M272570</link>
      <description>&lt;P&gt;Ideally, I would like to do the subsetting while importing.&lt;/P&gt;&lt;P&gt;The reason is that the rows that I would like to leave out&amp;nbsp;contain invalid data, and SAS&amp;nbsp;throws errors in the log when I import them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 07:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/338366#M272570</guid>
      <dc:creator>user_</dc:creator>
      <dc:date>2017-03-06T07:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Import rows of csv file except those satisfying conditions plus the previous/following ones</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/338962#M272571</link>
      <description>&lt;P&gt;The following may be overkill, but it does let you read the data twice, get rid of the undesired records, yet result it no errors in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data recs (keep=_recnum);
  infile '/folders/myfolders/datahave.txt' end=eof;
  do until (eof);
    input;
    rec_count+1;
    if scan(_infile_,1) eq 'paris' then do;
      _recnum=rec_count;
      output;
      _recnum=rec_count-1;
      output;
    end;
    else if scan(_infile_,1) eq 'madrid' then do;
      _recnum=rec_count;
      output;
      _recnum=rec_count-1;
      output;
      _recnum=rec_count+1;
      output;
    end;
  end;
run;
data want (drop=_:);
  array _drops (999999) _temporary_;
  do until (eof1);
    set recs end=eof1;
    _rec_num+1;
    _drops(_rec_num)=_recnum;
  end;
  _rec_num=0;
  infile '/folders/myfolders/datahave.txt' end=eof2;
  do until (eof2);
    _rec_num+1;
    input @;
    if _rec_num not in _drops then do;
      input var1$ var2 var3;
      output;
    end;
    else input;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 19:53:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-rows-of-csv-file-except-those-satisfying-conditions-plus/m-p/338962#M272571</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-07T19:53:44Z</dc:date>
    </item>
  </channel>
</rss>

