<?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 Importing unstructured data stored in varying number of lines in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855020#M337953</link>
    <description>&lt;P&gt;As a personal project I would like to import Instagram data which I have dummied up in the file igdata_dummy.txt&lt;/P&gt;
&lt;P&gt;The data file structure is as follows, each on separate line: &lt;BR /&gt;1. Header record is as "Username's profile picture"&lt;BR /&gt;2. Username's ID&amp;nbsp;&lt;BR /&gt;3. Period "." if he Username is not followed back&lt;BR /&gt;4. Username's name (optional)&lt;/P&gt;
&lt;PRE&gt;filename igdat  '~/dat/igdata_dummy.txt';
data want;
  infile igdat truncover end=eof;
  length header $200 ID_ig $50 Follower $1 Username $100 ;
      input @@ ;
      if scan(_infile_,-1)= 'picture' and not eof then do;
        input header &amp;amp;;
        input ID_ig;
       if _infile_= '.' then 
       input Follower ;       
        else input Username &amp;amp;;        
     end; 
     output;   
   run;
proc print n;
run;&lt;/PRE&gt;
&lt;P&gt;Content of&amp;nbsp; file igdata_dummy.txt&lt;/P&gt;
&lt;PRE&gt;Johnsmith's profile picture
Johnsmith
·
John Smith
BW_photo's profile picture
BW_photo
Ansel Adams
IG.user's profile picture
IG.user
&lt;/PRE&gt;
&lt;P&gt;Desired output&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_0-1674417042106.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79593i4452A385FD88A68B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_0-1674417042106.png" alt="ghosh_0-1674417042106.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I would appreciate your suggestions in importing this data set.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Sun, 22 Jan 2023 22:36:59 GMT</pubDate>
    <dc:creator>ghosh</dc:creator>
    <dc:date>2023-01-22T22:36:59Z</dc:date>
    <item>
      <title>Importing unstructured data stored in varying number of lines</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855020#M337953</link>
      <description>&lt;P&gt;As a personal project I would like to import Instagram data which I have dummied up in the file igdata_dummy.txt&lt;/P&gt;
&lt;P&gt;The data file structure is as follows, each on separate line: &lt;BR /&gt;1. Header record is as "Username's profile picture"&lt;BR /&gt;2. Username's ID&amp;nbsp;&lt;BR /&gt;3. Period "." if he Username is not followed back&lt;BR /&gt;4. Username's name (optional)&lt;/P&gt;
&lt;PRE&gt;filename igdat  '~/dat/igdata_dummy.txt';
data want;
  infile igdat truncover end=eof;
  length header $200 ID_ig $50 Follower $1 Username $100 ;
      input @@ ;
      if scan(_infile_,-1)= 'picture' and not eof then do;
        input header &amp;amp;;
        input ID_ig;
       if _infile_= '.' then 
       input Follower ;       
        else input Username &amp;amp;;        
     end; 
     output;   
   run;
proc print n;
run;&lt;/PRE&gt;
&lt;P&gt;Content of&amp;nbsp; file igdata_dummy.txt&lt;/P&gt;
&lt;PRE&gt;Johnsmith's profile picture
Johnsmith
·
John Smith
BW_photo's profile picture
BW_photo
Ansel Adams
IG.user's profile picture
IG.user
&lt;/PRE&gt;
&lt;P&gt;Desired output&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_0-1674417042106.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79593i4452A385FD88A68B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_0-1674417042106.png" alt="ghosh_0-1674417042106.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I would appreciate your suggestions in importing this data set.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2023 22:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855020#M337953</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2023-01-22T22:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Importing unstructured data stored in varying number of lines</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855028#M337955</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover ;
input have $100.;
cards;
Johnsmith's profile picture
Johnsmith
·
John Smith
BW_photo's profile picture
BW_photo
Ansel Adams
IG.user's profile picture
IG.user
;
run;
data temp;
 set have;
 length temp name $ 100;
 retain temp;
 if findw(have,'profile') and findw(have,'picture') then do;
  id+1;n=1;temp=scan(have,1,"'");name='header';
 end;
    else if  have=:temp then do;n=2;name='ID_ig';end;
      else if strip(have)='·' or missing(have) then do;n=3;name='Follower';end;
	    else do;n=4;name='Username';end;
drop temp;
run;
proc transpose data=temp out=want(drop=_:);
by id;
id name;
var have;
run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1674448889769.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79594iFD076C6F2CF75F59/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1674448889769.png" alt="Ksharp_0-1674448889769.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 04:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855028#M337955</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-01-23T04:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Importing unstructured data stored in varying number of lines</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855246#M338040</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for taking the time to give me a solution.&amp;nbsp; However, if the Username's ID and the Username's name have identical values it throws an error.&amp;nbsp; I have updated the dummy data to re-create the error shown below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover ;
input have $100.;
cards;
Johnsmith's profile picture
Johnsmith
·
Johnsmith
BW_photo's profile picture
BW_photo
Ansel Adams
IG.user's profile picture
IG.user
IG.user
;
run;
data temp;
 set have;
 length temp name $ 100;
 retain temp;
 if findw(have,'profile') and findw(have,'picture') then do;
  id+1;n=1;temp=scan(have,1,"'");name='header';
 end;
    else if  have=:temp then do;n=2;name='ID_ig';end;
      else if strip(have)='·' or missing(have) then do;n=3;name='Follower';end;
	    else do;n=4;name='Username';end;
drop temp;
run;
proc transpose data=temp out=want(drop=_:);
by id;
id name;
var have;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_0-1674510090317.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79671i03DD76E3C79AAAFD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_0-1674510090317.png" alt="ghosh_0-1674510090317.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 21:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855246#M338040</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2023-01-23T21:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Importing unstructured data stored in varying number of lines</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855280#M338057</link>
      <description>&lt;P&gt;OK. Try this one :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover ;
input have $100.;
cards;
Johnsmith's profile picture
Johnsmith
·
Johnsmith
BW_photo's profile picture
BW_photo
Ansel Adams
IG.user's profile picture
IG.user
IG.user
;
run;
data temp;
 set have;
 length temp name $ 100;
 retain temp found;
 if findw(have,'profile') and findw(have,'picture') then do;
  id+1;n=1;temp=scan(have,1,"'");name='header';found=0;
 end;
    else if  have=:temp and not found then do;n=2;name='ID_ig';found=1;end;
      else if strip(have)='·' or missing(have) then do;n=3;name='Follower';end;
	    else do;n=4;name='Username';end;
drop temp found;
run;
proc transpose data=temp out=want(drop=_:);
by id;
id name;
var have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1674533507716.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79674i292C7B4996EFB858/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1674533507716.png" alt="Ksharp_0-1674533507716.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 04:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855280#M338057</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-01-24T04:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Importing unstructured data stored in varying number of lines</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855496#M338104</link>
      <description>thanks!</description>
      <pubDate>Wed, 25 Jan 2023 03:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-unstructured-data-stored-in-varying-number-of-lines/m-p/855496#M338104</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2023-01-25T03:46:12Z</dc:date>
    </item>
  </channel>
</rss>

