<?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 TXT File with only one line of data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402238#M97659</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;Yes that's a better solution. Slow brain this Monday morning. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Oct 2017 00:34:26 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2017-10-09T00:34:26Z</dc:date>
    <item>
      <title>Reading a TXT File with only one line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402221#M97648</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;I'm quite new to SAS, I'm in a class at university and I have scoured the internet for an answer to this question and have come up with nothing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In SAS Studio, I'm attempting to read a txt file of an answer key. The answers are all on one line, delimited by a comma. However, I'd like each answer to fill an observation, not a different variable, so I can compare the answer key to another data file where the answers are observations, and my assignment says we cannot change the .txt file (I would personally just like to go in and put each answer on a separate line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is, how can I read this one line of data as one variable "Answer" with each answer as an observation, not a variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data anskey;&lt;BR /&gt;infile '/home/jacobrobertwest0/hw/A1_Ans_only.txt' dlm=',';&lt;BR /&gt;input answer $;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I do this, it shows up as a single variable "answer" with one observation, just the first answer on the txt file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2017 21:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402221#M97648</guid>
      <dc:creator>jacobrwest</dc:creator>
      <dc:date>2017-10-08T21:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a TXT File with only one line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402226#M97650</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file "%sysfunc(pathname(work))\t.txt";
  put 'a,vbb,sdfs,erw,3';
run;

data WANT;
  infile "%sysfunc(pathname(work))\t.txt" dlm=',' pad;
  length VAR $8;
  do until(VAR=' ');
    input VAR : $8. @;
    output;
  end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;VAR&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;vbb&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;sdfs&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;erw&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2017 23:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402226#M97650</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-10-08T23:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a TXT File with only one line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402227#M97651</link>
      <description>&lt;P&gt;If you want to avoid the LOST CARD &amp;nbsp;message in the log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  infile "%sysfunc(pathname(work))\t.txt" dlm=',' pad end=EOF;
  length VAR $8;
  input @;
  NBVARS=countw(_infile_,',');
  do I=1 TO NBVARS;
    input VAR : $8. @;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2017 23:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402227#M97651</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-10-08T23:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a TXT File with only one line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402232#M97656</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/164308"&gt;@jacobrwest&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Or as a variation to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename myData temp;
data _null_;
  file myData;
  put 'a,vbb,sdfs,erw,3,,99';
run;

data WANT;
  infile myData dlm=',' dsd;
  input var :$8. @@;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;@@ will hold the input buffer on the same line during iteration of the data step.&lt;/P&gt;
&lt;P&gt;In each iteration a position of your source data will be read, then the data step will loop again (input cursor still on the same line but now starting at the position where it was at the end of the previous iteration). So you read once "cell" of data per iteration of the data step.&lt;/P&gt;
&lt;P&gt;If there is no explicit &lt;EM&gt;output&amp;nbsp;&lt;/EM&gt;in your data step then an implicit &lt;EM&gt;output&amp;nbsp;&lt;/EM&gt;will get executed at the end of each iteration.&lt;/P&gt;
&lt;P&gt;The data step will stop execution when the input pointer reaches the end of your source data (=last value read).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And here the docu link you couldn't find:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n0oaql83drile0n141pdacojq97s.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p0touy66sj3jaen11n1kbudqdwd4&amp;nbsp;" target="_blank"&gt;http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n0oaql83drile0n141pdacojq97s.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p0touy66sj3jaen11n1kbudqdwd4&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I normally restrict my searches to the SAS site. I.e. to find above link my search term has been:&lt;/P&gt;
&lt;P&gt;site:support.sas.com 9.4 input statement @@&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 00:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402232#M97656</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-09T00:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a TXT File with only one line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402238#M97659</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;Yes that's a better solution. Slow brain this Monday morning. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 00:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-TXT-File-with-only-one-line-of-data/m-p/402238#M97659</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-10-09T00:34:26Z</dc:date>
    </item>
  </channel>
</rss>

