<?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: Text file to SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634472#M188309</link>
    <description>&lt;P&gt;You need a way to figure out how many allergies to read or to read until you find the next NAME.&amp;nbsp; This assumes that each allergy begins with ALLERGY.&amp;nbsp; Show data this is more realistic to your actual data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename FT15F001 temp;
data test;
   retain;
   infile FT15F001 length=l;
   length Name $32 Sex $1 Age 8 Country $8 Allergy $5;
   input name / sex= / age= / country= / allergy=;
   if first(allergy) eq 'T' then do;
      input atype:&amp;amp;$32. @; 
      do while(atype eq: 'Allergy');
         output;
         input / atype:&amp;amp;$32. @1 @@;
         end;
      call missing(atype);
      end;
   else output;
   return;
   parmcards;
John
Sex=M
Age=31
Country=US
Allergy=False
Mark
Sex=M
Age=32
Country=US
Allergy=True
Allergy1
Allergy2
Allergy3
Chase
Sex=F
Age=34
Country=UK
Allergy=False
;;;;
   run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 587px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37298i08C6711D8CA23102/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Mar 2020 16:07:55 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2020-03-24T16:07:55Z</dc:date>
    <item>
      <title>Text file to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634443#M188298</link>
      <description>&lt;P&gt;Can someone please help me on how to read the below text file format to SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;John&lt;BR /&gt;Sex=M&lt;BR /&gt;Age=31&lt;BR /&gt;Country=US&lt;BR /&gt;Allergy=False&lt;BR /&gt;Mark&lt;BR /&gt;Sex=M&lt;BR /&gt;Age=32&lt;BR /&gt;Country=US&lt;BR /&gt;Allergy=True&lt;BR /&gt;Allergy1&lt;BR /&gt;Allergy2&lt;BR /&gt;Allergy3&lt;BR /&gt;Chase&lt;BR /&gt;Sex=F&lt;BR /&gt;Age=34&lt;BR /&gt;Country=UK&lt;BR /&gt;Allergy=False&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried simple infile statement and using / but that works if data is consistent. In my case the pattern changes slightly if Allergy field is true. Appreciate your help.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 14:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634443#M188298</guid>
      <dc:creator>vak1987</dc:creator>
      <dc:date>2020-03-24T14:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Text file to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634448#M188299</link>
      <description>Are there any blank lines that you are not showing.</description>
      <pubDate>Tue, 24 Mar 2020 14:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634448#M188299</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2020-03-24T14:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Text file to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634450#M188300</link>
      <description>&lt;P&gt;Nope, text file does not have any blank lines.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 15:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634450#M188300</guid>
      <dc:creator>vak1987</dc:creator>
      <dc:date>2020-03-24T15:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Text file to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634472#M188309</link>
      <description>&lt;P&gt;You need a way to figure out how many allergies to read or to read until you find the next NAME.&amp;nbsp; This assumes that each allergy begins with ALLERGY.&amp;nbsp; Show data this is more realistic to your actual data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename FT15F001 temp;
data test;
   retain;
   infile FT15F001 length=l;
   length Name $32 Sex $1 Age 8 Country $8 Allergy $5;
   input name / sex= / age= / country= / allergy=;
   if first(allergy) eq 'T' then do;
      input atype:&amp;amp;$32. @; 
      do while(atype eq: 'Allergy');
         output;
         input / atype:&amp;amp;$32. @1 @@;
         end;
      call missing(atype);
      end;
   else output;
   return;
   parmcards;
John
Sex=M
Age=31
Country=US
Allergy=False
Mark
Sex=M
Age=32
Country=US
Allergy=True
Allergy1
Allergy2
Allergy3
Chase
Sex=F
Age=34
Country=UK
Allergy=False
;;;;
   run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 587px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37298i08C6711D8CA23102/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 16:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634472#M188309</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2020-03-24T16:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: Text file to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634473#M188310</link>
      <description>&lt;P&gt;Is there any rule when this file was built that determines that your (likely) name is separated from the last allergy?&lt;/P&gt;
&lt;P&gt;Is there a limit on the number of allergies per person?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show what a SAS data set from this example should look like after it is read.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 16:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634473#M188310</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-24T16:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Text file to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634699#M188401</link>
      <description>Plz post the output you are looking for .</description>
      <pubDate>Wed, 25 Mar 2020 11:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634699#M188401</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-25T11:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Text file to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634831#M188430</link>
      <description>&lt;P&gt;Assuming that you always have NAME/SEX/AGE/COUNTRY/ALLERGY for each subject here is one way.&lt;/P&gt;
&lt;P&gt;Read the file once looking for lines that start with SEX= to find the number of subjects and where they start.&lt;/P&gt;
&lt;P&gt;Then on reading the second time you can know how many lines to read for the allergans list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename text temp;
options parmcards=text;
parmcards;
John
Sex=M
Age=31
Country=US
Allergy=False
Mark
Sex=M
Age=32
Country=US
Allergy=True
Allergy1
Allergy2
Allergy3
Chase
Sex=F
Age=34
Country=UK
Allergy=False
;
data list ;
  if eof then call symputx('nlines',_n_);
  infile text end=eof;
  retain id 0 start_row -1;
  input;
  start_row+1;
  if _infile_=: 'Sex=' then do; id+1; output; end;
run;

data list;
  set list end=eof;
  if eof then last_row=&amp;amp;nlines;
  else set list(firstobs=2 keep=start_row rename=start_row=last_row);
  last_row=last_row-1;
run;

data want;
  set list ;
  infile text truncover ;
  length name $30 sex $1 age 8 country $20 Allergy $5 Allergy_list $200 ;
  input name / @5 sex / @5 age/ @9 country / @9 Allergy;
  do _n_=start_row+5 to last_row;
    input; allergy_list=catx('|',allergy_list,_infile_);
  end;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;             start_
Obs    id      row     last_row    name     sex    age    country    Allergy           Allergy_list

 1      1       1          5       John      M      31      US        False
 2      2       6         13       Mark      M      32      US        True      Allergy1|Allergy2|Allergy3
 3      3      14         18       Chase     F      34      UK        False
&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Mar 2020 17:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/634831#M188430</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-25T17:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: Text file to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/635005#M188510</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards truncover;
input temp $100.;
cards;
John
Sex=M
Age=31
Country=US
Allergy=False
Mark
Sex=M
Age=32
Country=US
Allergy=True
Allergy1
Allergy2
Allergy3
Chase
Sex=F
Age=34
Country=UK
Allergy=False
;
data temp;
merge test test(firstobs=2 rename=(temp=_temp));
if _temp =: 'Sex=' then group+1;
run;
data temp;
 set temp;
 by group;
 length name $ 40;
 if first.group then do;n=0;name='Name';value=temp;end;
  else if findc(temp,'=') then do;name=scan(temp,1,'=');value=scan(temp,-1,'=');end;
   else do;n+1;name=cats('Allergy',n);value=temp;end;
keep name value group;
run;
proc transpose data=temp out=want(drop=_name_);
by group;
id name;
var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Mar 2020 11:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-file-to-SAS/m-p/635005#M188510</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-26T11:23:02Z</dc:date>
    </item>
  </channel>
</rss>

