<?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 Input Statement - Can we move back on the dataline being read - in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539892#M7142</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets say the data is as below&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bellatorum School: CSULA Time: 1:40.5&lt;BR /&gt;The Kraken School: ASU Time: 1:45.35&lt;BR /&gt;Black Widow School: UoA Time: 1:33.7&lt;BR /&gt;Koicrete School: CSUF Time: 1:40.25&lt;BR /&gt;Khaos School: UNLV Time: 2:03.45&lt;BR /&gt;Max School: UCSD Time: 1:26.47&lt;BR /&gt;Hakuna Matata School: UCLA Time: 1:20.64&lt;BR /&gt;Prospector School: CPSLO Time: 1:12.08&lt;BR /&gt;Andromeda School: CPP Time: 1:25.1&lt;BR /&gt;Kekoapohaku School: UHM Time: 1:24.49&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if I want to read the text before the word "School:" how to go about it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;@n is useful to move to a column, but I want to identify a column&amp;nbsp;@'School:' and move back from there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively can we track the&amp;nbsp;@n column where the dataline is held and use it to a calculation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*being a noob, pls be kind ;&lt;/P&gt;</description>
    <pubDate>Sun, 03 Mar 2019 13:43:31 GMT</pubDate>
    <dc:creator>skt</dc:creator>
    <dc:date>2019-03-03T13:43:31Z</dc:date>
    <item>
      <title>Input Statement - Can we move back on the dataline being read -</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539892#M7142</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets say the data is as below&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bellatorum School: CSULA Time: 1:40.5&lt;BR /&gt;The Kraken School: ASU Time: 1:45.35&lt;BR /&gt;Black Widow School: UoA Time: 1:33.7&lt;BR /&gt;Koicrete School: CSUF Time: 1:40.25&lt;BR /&gt;Khaos School: UNLV Time: 2:03.45&lt;BR /&gt;Max School: UCSD Time: 1:26.47&lt;BR /&gt;Hakuna Matata School: UCLA Time: 1:20.64&lt;BR /&gt;Prospector School: CPSLO Time: 1:12.08&lt;BR /&gt;Andromeda School: CPP Time: 1:25.1&lt;BR /&gt;Kekoapohaku School: UHM Time: 1:24.49&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if I want to read the text before the word "School:" how to go about it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;@n is useful to move to a column, but I want to identify a column&amp;nbsp;@'School:' and move back from there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively can we track the&amp;nbsp;@n column where the dataline is held and use it to a calculation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*being a noob, pls be kind ;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Mar 2019 13:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539892#M7142</guid>
      <dc:creator>skt</dc:creator>
      <dc:date>2019-03-03T13:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Input Statement - Can we move back on the dataline being read -</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539895#M7143</link>
      <description>&lt;P&gt;You can read the whole thing, then extract the text that you need. Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/td-p/62681" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/td-p/62681&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Mar 2019 14:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539895#M7143</guid>
      <dc:creator>Norman21</dc:creator>
      <dc:date>2019-03-03T14:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Input Statement - Can we move back on the dataline being read -</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539914#M7145</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/170677"&gt;@skt&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;@n is useful to move to a column, but I want to identify a column&amp;nbsp;@'School:' and move back from there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively can we track the&amp;nbsp;@n column where the dataline is held and use it to a calculation&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/170677"&gt;@skt&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess many people would indeed read the whole data line (e.g. using an "empty" INPUT statement so that the text is captured in automatic variable _INFILE_), then search for 'School' (e.g. using the FIND function to determine the position) and finally extract the appropriate substring (e.g. &lt;FONT face="courier new,courier"&gt;name=substr(_infile_,1,pos-2)&lt;/FONT&gt;), as suggested by Norman21.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But more specifically to your question: Yes, we can move back from the column we have found using the&amp;nbsp;@'&lt;EM&gt;character-string&lt;/EM&gt;' syntax and yes, we can track the position where the input pointer is currently located and use that in a calculation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile cards col=c;
input @'School' @;
c=c-8;
input @1 name $varying40. c;
cards;
Bellatorum School: CSULA Time: 1:40.5
The Kraken School: ASU Time: 1:45.35
Black Widow School: UoA Time: 1:33.7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;UL&gt;
&lt;LI&gt;I use the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;INFILE statement&lt;/A&gt; to make the COL= (or COLUMN=) option available.&lt;/LI&gt;
&lt;LI&gt;C is the (user-specified) name of a variable to store the current column location of the input pointer.&lt;/LI&gt;
&lt;LI&gt;After the first INPUT statement, C will contain the position (column number) of the first character following the word "School".&lt;/LI&gt;
&lt;LI&gt;The trailing "@" holds the input record so that the second INPUT statement can read from it, too.&lt;/LI&gt;
&lt;LI&gt;By subtracting 8 (or 7), C gets the position of the last character of the name (or of the following blank, respectively).&lt;/LI&gt;
&lt;LI&gt;This value is used as the length specification for the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=leforinforref&amp;amp;docsetTarget=n00h0tql17cempn1kwjdbjdktpr3.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;$VARYING40. informat&lt;/A&gt;. which reads the name as a string of the specified length (max. 40 -- increase the number if you're not sure that 40 is sufficient) after the input pointer has been moved back to column 1 by means of the "@1" column pointer control.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Note that the&amp;nbsp;@'&lt;EM&gt;character-string&lt;/EM&gt;' syntax lets SAS go to the next line if '&lt;EM&gt;character-string&lt;/EM&gt;' is not found. So, records not containing the word "School" would be skipped and a note in the log "&lt;FONT face="courier new,courier"&gt;NOTE: SAS went to a new line ...&lt;/FONT&gt;" would indicate this. The other suggested method would be more flexible regarding this situation. For example, if "School" was not found, a different assignment statement could be executed (e.g.&amp;nbsp;&lt;FONT face="courier new,courier"&gt;name=scan(_infile_,1,':')&lt;/FONT&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Changed all occurrences of "schoolname" and "school name" to "name" after realizing that CSULA, ASU etc. are the real "school" (i.e. university) names. Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;for clarifying this for the non-native speakers. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Mar 2019 19:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539914#M7145</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-03-03T19:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Input Statement - Can we move back on the dataline being read -</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539915#M7146</link>
      <description>&lt;P&gt;If you want a more &lt;EM&gt;arcane&lt;/EM&gt; solution, you could use a regular expression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want;

    length 
        SchoolName $ 50
        rx 8
    ;
    drop rx;
	
    input;
	
    rx = prxparse('/(.+) school.*/i');
	
    if prxmatch(rx, _infile_) then do;
        SchoolName = prxposn(rx, 1, _infile_);
    end;
	
    datalines;
Bellatorum School: CSULA Time: 1:40.5
The Kraken School: ASU Time: 1:45.35
Black Widow School: UoA Time: 1:33.7
Koicrete School: CSUF Time: 1:40.25
Khaos School: UNLV Time: 2:03.45
Max School: UCSD Time: 1:26.47
Hakuna Matata School: UCLA Time: 1:20.64
Prospector School: CPSLO Time: 1:12.08
Andromeda School: CPP Time: 1:25.1
Kekoapohaku School: UHM Time: 1:24.49
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Mar 2019 17:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539915#M7146</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-03T17:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Input Statement - Can we move back on the dataline being read -</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539930#M7149</link>
      <description>&lt;P&gt;Use the COL= option on the INFILE statement to have SAS tell you where the current pointer is.&lt;/P&gt;
&lt;P&gt;You can use&amp;nbsp;@ and + in INPUT statement to move the pointer if you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your particular example I wouldn't bother.&amp;nbsp; Just read the data using ':' as the delimiter.&amp;nbsp; Read the last field using a format so that it will read the colon's into the value.&amp;nbsp; Then remove the "School" and "Time" from the values and convert the time string into a format that SAS can interpret.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length name $50 school $20 time 8;
  infile datalines dsd dlm=':' truncover ;
  input x1 :$100. x2 :$100. x3 $100. ;
  drop x1-x3;
  name=tranwrd(x1,'School    ',' ');
  school=tranwrd(x2,'Time    ',' ');
  time=input(cats('00:',x3),time20.);
  format time time11.2;
datalines;
Bellatorum School: CSULA Time: 1:40.5
The Kraken School: ASU Time: 1:45.35
Black Widow School: UoA Time: 1:33.7
Koicrete School: CSUF Time: 1:40.25
Khaos School: UNLV Time: 2:03.45
Max School: UCSD Time: 1:26.47
Hakuna Matata School: UCLA Time: 1:20.64
Prospector School: CPSLO Time: 1:12.08
Andromeda School: CPP Time: 1:25.1
Kekoapohaku School: UHM Time: 1:24.49
;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    name             school           time

  1    Bellatorum       CSULA      0:01:40.50
  2    The Kraken       ASU        0:01:45.35
  3    Black Widow      UoA        0:01:33.70
  4    Koicrete         CSUF       0:01:40.25
  5    Khaos            UNLV       0:02:03.45
  6    Max              UCSD       0:01:26.47
  7    Hakuna Matata    UCLA       0:01:20.64
  8    Prospector       CPSLO      0:01:12.08
  9    Andromeda        CPP        0:01:25.10
 10    Kekoapohaku      UHM        0:01:24.49&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Mar 2019 19:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/539930#M7149</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-03T19:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Input Statement - Can we move back on the dataline being read -</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/540144#M7187</link>
      <description>&lt;P&gt;Having dealt with a similar issue I ask "Does &lt;STRONG&gt;ever&lt;/STRONG&gt;y single one of your schools have "School" as the last word when present?"&lt;/P&gt;
&lt;P&gt;I had to deal with "Idaho School for the Deaf and Blind" and "The School at &amp;lt;place name" constructs which meant more than a simple replacement was needed for a few cases.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 18:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Input-Statement-Can-we-move-back-on-the-dataline-being-read/m-p/540144#M7187</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-04T18:47:58Z</dc:date>
    </item>
  </channel>
</rss>

