<?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: series of do until to pick values out of a text file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522208#M141740</link>
    <description>&lt;P&gt;What you have there is a bit of a mess, ideally going back to source and getting actual data would be easier.&amp;nbsp; Anyways, if I had to do this, then I would just read in the whole file:&lt;/P&gt;
&lt;PRE&gt;data want;
  length line $;
  file ...;
  input line $;
  retain flag1;
  if flag=1 then do;   /* I.e. row has been found, so observations now are data */&lt;BR /&gt;    ...;&lt;BR /&gt;  end;&lt;BR /&gt;  if flag=2 then do;&lt;BR /&gt;    ...;&lt;BR /&gt;  end;
  if index(...) then flag=1;&lt;BR /&gt;  if index(...) then flag=2;&lt;BR /&gt;...&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;With that approach you can set numerous flags/counts etc. then just loop through the data, parsing what you need out.&lt;/P&gt;</description>
    <pubDate>Tue, 18 Dec 2018 13:39:15 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-12-18T13:39:15Z</dc:date>
    <item>
      <title>series of do until to pick values out of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522191#M141730</link>
      <description>&lt;P&gt;I&amp;nbsp;will be&amp;nbsp;looping through a series of text files that are outputted from another program. I need to read through each file once, pulling out certain values to build a table. There are similarities to the files, but the line numbers will vary. I have been working with do until() to look for keywords, and then input the correct values. I can get each do until() group to work singly, but when I put them in series, it bombs out. I have attached a sample file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test; 
length test $34. model $80. ;
infile "path\PRI018\TKN.txt" obs=60  missover;
f="F";   g="F";  
   do until(f="T");
     input test $ 2-35 @;
     if test ne 'Number of Observations           :' then delete;
   else do;
     input @40 n //// @40 POR $9.;
     f="T";
     put _n_;		
   end;
   end;
put POR;
   do until(g='T');
     input test2 $ 2-11 @;
     if test2 ne 'Ln(Load) =' then delete;
   else do;
     input @13 model &amp;amp; $80.;
     g="T";
     put _n_;
   end;
   end;
put model;		
drop test test2  f g ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What am I missing?&lt;/P&gt;&lt;P&gt;I'm using SAS 9.4 1M2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 13:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522191#M141730</guid>
      <dc:creator>Caroline</dc:creator>
      <dc:date>2018-12-18T13:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: series of do until to pick values out of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522197#M141735</link>
      <description>&lt;P&gt;You haven't actually said what you are trying to do or get out.&amp;nbsp; If I want to find strings in a text file then:&lt;/P&gt;
&lt;PRE&gt;data want;
  file...;
  input;
  if index(_infile_,"Number of Observations") or
     index(_infile_,"Ln(Load)") then output;
run;&lt;/PRE&gt;
&lt;P&gt;You can then post process what is output from that.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 13:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522197#M141735</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-18T13:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: series of do until to pick values out of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522205#M141738</link>
      <description>&lt;P&gt;I'm trying to get out a value that immediately follows what I've found. So if it finds "Ln(Load)=" then I want it to input the rest of that line "a0 + a1 LnQ + a2 LnQ^2 + a3 Sin(2 pi dtime) + a4 Cos(2 pi dtime)" as variable &lt;EM&gt;model&lt;/EM&gt;. The values need to be input in order. There are some values that I need once, but appear several times (for instance, I may search for "AMLE", but it appears for streamflow and concentration, but I only&amp;nbsp;want concentration).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are roughly a dozen different variables that I need to pick out of each file.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 13:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522205#M141738</guid>
      <dc:creator>Caroline</dc:creator>
      <dc:date>2018-12-18T13:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: series of do until to pick values out of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522208#M141740</link>
      <description>&lt;P&gt;What you have there is a bit of a mess, ideally going back to source and getting actual data would be easier.&amp;nbsp; Anyways, if I had to do this, then I would just read in the whole file:&lt;/P&gt;
&lt;PRE&gt;data want;
  length line $;
  file ...;
  input line $;
  retain flag1;
  if flag=1 then do;   /* I.e. row has been found, so observations now are data */&lt;BR /&gt;    ...;&lt;BR /&gt;  end;&lt;BR /&gt;  if flag=2 then do;&lt;BR /&gt;    ...;&lt;BR /&gt;  end;
  if index(...) then flag=1;&lt;BR /&gt;  if index(...) then flag=2;&lt;BR /&gt;...&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;With that approach you can set numerous flags/counts etc. then just loop through the data, parsing what you need out.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 13:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522208#M141740</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-18T13:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: series of do until to pick values out of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522210#M141741</link>
      <description>&lt;P&gt;When you put the loops together, here's what happens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The top loop works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The bottom loop begins, but the text "Ln(Load) = " doesn't appear for a few lines.&amp;nbsp; The first time it is not found, the DELETE statement executes.&amp;nbsp; This does not move you to the top of the DO UNTIL loop.&amp;nbsp; Rather, it moves you to the top of the entire DATA step, so the top loop will execute again.&amp;nbsp; And the top loop moves through the rest of the file without finding a match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While other simplifications may be possible, the simplest would be to change the bottom DELETE statement to an assignment statement:&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 string"&gt;  if test2 ne '&lt;/SPAN&gt;Ln&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;Load&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;' &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; g="F";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 13:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522210#M141741</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-12-18T13:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: series of do until to pick values out of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522216#M141744</link>
      <description>&lt;P&gt;That explains the results I was getting. The assignment statement actually puts it into an infinite loop because of the trailing&amp;nbsp;@ on the input test2 line. When I changed the line to&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if test2 ne 'Ln(Load) =' then input;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;it works perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 13:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522216#M141744</guid>
      <dc:creator>Caroline</dc:creator>
      <dc:date>2018-12-18T13:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: series of do until to pick values out of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522220#M141747</link>
      <description>&lt;P&gt;Of course.&amp;nbsp; Sorry I didn't catch that the first time.&amp;nbsp; Good luck.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 14:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/series-of-do-until-to-pick-values-out-of-a-text-file/m-p/522220#M141747</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-12-18T14:07:54Z</dc:date>
    </item>
  </channel>
</rss>

