<?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: infile conditonally by dataline style in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/415369#M101854</link>
    <description>&lt;P&gt;There may be an easier way, but the following should work:&lt;/P&gt;
&lt;PRE&gt;filename FT15F001 temp;
data have;
  infile FT15F001 truncover end=eof;
  retain Loc state city postcode code interest second_interest;
  informat Loc $3. state $10. city $12. postcode $5. code $2. interest $35. second_interest $35.;
  format Loc $3. state $10. city $12. postcode $5. code $2. interest $35. second_interest $35.;

  input @;
  if index(_infile_, 'code:') gt 0 then do;
    input @"code: " code @"interest: " interest &amp;amp;;
  end;
  else if index(_infile_, '2nd interest:') gt 0 then do;
    input @"2nd interest: " second_interest &amp;amp;;
  end;
  else do;
    if _n_ gt 1 and not missing(loc) then output;
    call missing(of _all_);
    input Loc state city  postcode;
  end;
  if eof then output;
  parmcards;
 100   Pahang     raub           27600
         code: 1A      interest:  Pine Tree Trail (Bukit Fraser)      
               2nd interest: Allan's Water (Bukit Fraser)
     
     
 500   Selangor   Klang          41000
         code: 2A      interest:  Taman Rakyat Klang
         
 400   Selangor   Subang Jaya    40150
;
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
    <pubDate>Wed, 22 Nov 2017 03:19:19 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-11-22T03:19:19Z</dc:date>
    <item>
      <title>infile conditonally by dataline style</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/415192#M101804</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need help for infile coding, my code as below, definitely I have misuse the variable _infile_.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;infile datalines truncover dsd;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;format Loc $3. state $10. city $12. postcode $5. code $2. interest $35. second_interest $35.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input @;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input Loc $ 2-5 state $ 8-18&amp;nbsp; city $ 19-31 postcode $ 34-39;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if index(_infile_, 'code:') then &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;code = _infile_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if index(_infile_, 'interest:') then &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;interest = _infile_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;second_interest = _infile_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;datalines;&lt;BR /&gt;&amp;nbsp;100&amp;nbsp;&amp;nbsp; Pahang&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raub&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 27600&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; code: 1A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; interest:&amp;nbsp; Pine Tree Trail (Bukit Fraser)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2nd interest: Allan's Water (Bukit Fraser)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;500&amp;nbsp;&amp;nbsp; Selangor&amp;nbsp;&amp;nbsp; Klang&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 41000&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; code: 2A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; interest:&amp;nbsp; Taman Rakyat Klang&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;400&amp;nbsp;&amp;nbsp; Selangor&amp;nbsp;&amp;nbsp; Subang Jaya&amp;nbsp;&amp;nbsp;&amp;nbsp; 40150&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Basically the dataline was in 3 style and it can appear 1, 2, 3 and so on, any numbers. I'm believe there a code that infile each of the line depend the dataline style and input into SAS dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciated your help and advice&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 14:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/415192#M101804</guid>
      <dc:creator>sagulolo</dc:creator>
      <dc:date>2017-11-21T14:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: infile conditonally by dataline style</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/415194#M101805</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;re post my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines truncover dsd;
	format Loc $3. state $10. city $12. postcode $5. code $2. interest $35. second_interest $35.;
	
	input @;
	
	input Loc $ 2-5 state $ 8-18  city $ 19-31 postcode $ 34-39;
	
	if index(_infile_, 'code:') then 
		code = _infile_;
	
	else if index(_infile_, 'interest:') then 
		interest = _infile_;
	
	else
		second_interest = _infile_;
	
datalines;
 100   Pahang     raub           27600
         code: 1A      interest:  Pine Tree Trail (Bukit Fraser)      
               2nd interest: Allan's Water (Bukit Fraser)
     
     
 500   Selangor   Klang          41000
         code: 2A      interest:  Taman Rakyat Klang
         
 400   Selangor   Subang Jaya    40150
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Nov 2017 14:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/415194#M101805</guid>
      <dc:creator>sagulolo</dc:creator>
      <dc:date>2017-11-21T14:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: infile conditonally by dataline style</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/415366#M101851</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologize for forgot to put my expected output, kindly refer below:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Loc&lt;/TD&gt;&lt;TD&gt;state&lt;/TD&gt;&lt;TD&gt;city&lt;/TD&gt;&lt;TD&gt;postcode&lt;/TD&gt;&lt;TD&gt;code&lt;/TD&gt;&lt;TD&gt;interest&lt;/TD&gt;&lt;TD&gt;second_interest&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;Pahang&lt;/TD&gt;&lt;TD&gt;raub&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;27600&lt;/TD&gt;&lt;TD&gt;1A&lt;/TD&gt;&lt;TD&gt;Pine Tree Trail (Bukit Fraser)&lt;/TD&gt;&lt;TD&gt;Allan's Water (Bukit Fraser)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;TD&gt;Selangor&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;Klang&lt;/TD&gt;&lt;TD&gt;41000&lt;/TD&gt;&lt;TD&gt;2A&lt;/TD&gt;&lt;TD&gt;Taman Rakyat Klang&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;TD&gt;Selangor&lt;/TD&gt;&lt;TD&gt;Subang Jaya&lt;/TD&gt;&lt;TD&gt;40150&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 22 Nov 2017 02:41:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/415366#M101851</guid>
      <dc:creator>sagulolo</dc:creator>
      <dc:date>2017-11-22T02:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: infile conditonally by dataline style</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/415369#M101854</link>
      <description>&lt;P&gt;There may be an easier way, but the following should work:&lt;/P&gt;
&lt;PRE&gt;filename FT15F001 temp;
data have;
  infile FT15F001 truncover end=eof;
  retain Loc state city postcode code interest second_interest;
  informat Loc $3. state $10. city $12. postcode $5. code $2. interest $35. second_interest $35.;
  format Loc $3. state $10. city $12. postcode $5. code $2. interest $35. second_interest $35.;

  input @;
  if index(_infile_, 'code:') gt 0 then do;
    input @"code: " code @"interest: " interest &amp;amp;;
  end;
  else if index(_infile_, '2nd interest:') gt 0 then do;
    input @"2nd interest: " second_interest &amp;amp;;
  end;
  else do;
    if _n_ gt 1 and not missing(loc) then output;
    call missing(of _all_);
    input Loc state city  postcode;
  end;
  if eof then output;
  parmcards;
 100   Pahang     raub           27600
         code: 1A      interest:  Pine Tree Trail (Bukit Fraser)      
               2nd interest: Allan's Water (Bukit Fraser)
     
     
 500   Selangor   Klang          41000
         code: 2A      interest:  Taman Rakyat Klang
         
 400   Selangor   Subang Jaya    40150
;
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 03:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/415369#M101854</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-11-22T03:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: infile conditonally by dataline style</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/417074#M102430</link>
      <description>&lt;P&gt;Hi art297,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the code and sorry for the delay.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It really help me a lot, do you mind to explained this part:-&lt;/P&gt;&lt;PRE&gt;input @"code: " code @"interest: " interest &amp;amp;;&lt;/PRE&gt;&lt;P&gt;I have another issue,&amp;nbsp; data sample per below:-&lt;/P&gt;&lt;PRE&gt;         code:         interest:  Taman Rakyat Klang&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The field code should be null, but field code is 'in' instead of null. How to fix it if data is null?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 14:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/417074#M102430</guid>
      <dc:creator>sagulolo</dc:creator>
      <dc:date>2017-11-29T14:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: infile conditonally by dataline style</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/417096#M102439</link>
      <description>&lt;P&gt;There are a number of ways to specify how to read data into SAS. Rather than me trying to re-write the documentation, take a look at:&amp;nbsp;&lt;A href="https://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003209907.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003209907.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, quick answer to your questions: using something like&amp;nbsp;@"code" code&lt;/P&gt;
&lt;P&gt;searches your datafile for the string "code", then inputs whatever is there. However, it will ignore blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the codes are always in the same position, as in your example, then the following should work:&lt;/P&gt;
&lt;PRE&gt;filename FT15F001 temp;
data have;
  infile FT15F001 truncover end=eof;
  retain Loc state city postcode code interest second_interest;
  informat Loc $3. state $10. city $12. postcode $5. code $2. interest $35. second_interest $35.;
  format Loc $3. state $10. city $12. postcode $5. code $2. interest $35. second_interest $35.;
  input @;
  if index(_infile_, 'code:') gt 0 then do;
    input code 16-17 @"interest: " interest &amp;amp;;
  end;
  else if index(_infile_, '2nd interest:') gt 0 then do;
    input @"2nd interest: " second_interest &amp;amp;;
  end;
  else do;
    if _n_ gt 1 and not missing(loc) then output;
    call missing(of _all_);
    input Loc state city  postcode;
  end;
  if eof then output;
  parmcards;
 100   Pahang     raub           27600
         code: 1A      interest:  Pine Tree Trail (Bukit Fraser)      
               2nd interest: Allan's Water (Bukit Fraser)
 300   Telangor   Klang          41000
         code:         interest:  Something else
         
 500   Selangor   Klang          41000
         code: 2A      interest:  Taman Rakyat Klang
         
 400   Selangor   Subang Jaya    40150
;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infile-conditonally-by-dataline-style/m-p/417096#M102439</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-11-29T15:40:02Z</dc:date>
    </item>
  </channel>
</rss>

