<?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 an .fdf file into SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791154#M253363</link>
    <description>&lt;P&gt;That does not look like the right output for that input file.&amp;nbsp; One of the &amp;lt;&amp;lt;/Content( strings is missing the slash.&lt;/P&gt;
&lt;P&gt;First let's make an actual text file we can use as input.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options parmcards=fdf ;
filename fdf temp;
parmcards4;
askdjf;lk
fdasfe
qweiopqwur
&amp;lt;&amp;lt;/Contents(variable1)-akljsdfkj
Page 1&amp;gt;&amp;gt;&amp;lt;&amp;lt;xj/variable2-akljsdfkj Page 1&amp;gt;&amp;gt;&amp;lt;&amp;lt;/Contents(variable2) -akljsdfkj
Page 4&amp;gt;&amp;gt;4564324&amp;lt;&amp;lt;/Contents(variable2-akljsdfkj Page 2&amp;gt;&amp;gt;&amp;lt;&amp;lt;Contents(ar/variable1)-akljsdfkj
Page 3&amp;gt;&amp;gt;
&amp;lt;&amp;lt;/Contents(variable1) -akljsdfkj
Page 4&amp;gt;&amp;gt;

hjkasdfkjhsdfe
;;;;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's use the&amp;nbsp;@ command to find the starting points and the SCAN() function to remove the trailing letters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile fdf column=cc ;
  input @'&amp;lt;&amp;lt;/Contents(' variable :$200. @;
  variable=scan(variable,1,')');
  input @'Page ' @ ;
  s = cc ;
  input string :$20. @;
  Page = scan(string,1,'&amp;gt;') ;
  output;
  input @s @@;
  drop s string;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    variable               Page

 1     variable1               1
 2     variable2               4
 3     variable2-akljsdfkj     2
 4     variable1               4
&lt;/PRE&gt;
&lt;P&gt;If there are limits on what characters can be valid in the variable name then it could be even simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile fdf flowover dlm=')&amp;gt; ';
  input @'&amp;lt;&amp;lt;/Contents(' variable :$200. @'Page ' page @@ ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 20 Jan 2022 14:49:47 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-01-20T14:49:47Z</dc:date>
    <item>
      <title>Reading an .fdf file into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791118#M253348</link>
      <description>&lt;P&gt;Hi community.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to parse an .fdf file that looks something like this:&lt;/P&gt;&lt;P&gt;File.fdf&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------&lt;/P&gt;&lt;P&gt;askdjf;lk&lt;BR /&gt;fdasfe&lt;BR /&gt;qweiopqwur&lt;BR /&gt;&amp;lt;&amp;lt;/Contents(variable1)-akljsdfkj&lt;BR /&gt;Page 1&amp;gt;&amp;gt;&amp;lt;&amp;lt;xj/variable2-akljsdfkj Page 1&amp;gt;&amp;gt;&amp;lt;&amp;lt;/Contents(variable2) -akljsdfkj&lt;BR /&gt;Page 4&amp;gt;&amp;gt;4564324&amp;lt;&amp;lt;/Contents(variable2-akljsdfkj Page 2&amp;gt;&amp;gt;&amp;lt;&amp;lt;Contents(ar/variable1)-akljsdfkj&lt;BR /&gt;Page 3&amp;gt;&amp;gt;&lt;BR /&gt;&amp;lt;&amp;lt;/Contents(variable1) -akljsdfkj&lt;BR /&gt;Page 4&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;hjkasdfkjhsdfe&lt;/P&gt;&lt;P&gt;-------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I basically want to recover (1) the variable names that are always in-between "Contents(" and the next ")", and (2) the corresponding page number that is always after "Page " and before the next "&amp;gt;&amp;gt;".&lt;/P&gt;&lt;P&gt;I have been trying to use a DATA step with an INFILE. The issues I have been encountering are about how to read several VARIABLES and PAGES from a single _INFILE_ line, since I can make it work to read a single VARIABLE and PAGE per input line. This is compounded with the fact that the lines are way too long in the .fdf file (&amp;gt; 50,000 characters).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way in which perhaps I can split the file directly from SAS into different lines? This is more or less what I have tried so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS_SCRIPT&lt;/P&gt;&lt;P&gt;------------------------------------------------------------&lt;/P&gt;&lt;P&gt;data;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile "file.fdf" linesize=32767 N=10000;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*Gather occurrence for the loop*/&lt;BR /&gt;&amp;nbsp; vars =countc(_infile_,"Contents(");&lt;BR /&gt;&amp;nbsp; pags=countc(_infile_,"Page ");&lt;/P&gt;&lt;P&gt;&amp;nbsp; pos=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Start loop to find all occurrences of variables */&lt;BR /&gt;&amp;nbsp; do i=0 TO min(vars,pags);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; pos_var = find(_infile_, "Contents(",pos)+9;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if ( pos_var &amp;gt; 9 ) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; pos = pos_var;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; length_var =&amp;nbsp;find(_infile_, ")",pos_var) - pos_var;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if ( length_var &amp;gt; )&amp;nbsp;then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pos_page = find(_infile_,")",pos_var) + 5;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ( pos_page &amp;gt; 5 ) then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; length_page =&amp;nbsp;find(_infile_, "&amp;gt;",pos_page) - pos_page;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ( length_page &amp;gt; 0 )&amp;nbsp;then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* Now input */&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var = substr(_infile_, pos_var, length_var);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; page = substr(_infile_, pos_page, length_page);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;------------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output&lt;/P&gt;&lt;P&gt;-------------------------------------------------------&lt;/P&gt;&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;page&lt;/P&gt;&lt;P&gt;variable1&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;variable1&amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;variable 2&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;.... etc&lt;/P&gt;&lt;P&gt;-------------------------------------------------------&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 14:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791118#M253348</guid>
      <dc:creator>LuisB</dc:creator>
      <dc:date>2022-01-20T14:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an .fdf file into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791121#M253350</link>
      <description>I also tried, unsuccessfully. the following:&lt;BR /&gt;-----------------------------------------&lt;BR /&gt;data work.import;&lt;BR /&gt;infile 'file.fdf' linesize 32767;&lt;BR /&gt;length page $3.;&lt;BR /&gt;&lt;BR /&gt;do i=0 to 1000 until (page='');&lt;BR /&gt;input&lt;BR /&gt;@'Contents(' variable $30.&lt;BR /&gt;@'Page ' page $3. @;&lt;BR /&gt;end;&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;BR /&gt;-------------------------------------</description>
      <pubDate>Thu, 20 Jan 2022 11:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791121#M253350</guid>
      <dc:creator>LuisB</dc:creator>
      <dc:date>2022-01-20T11:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an .fdf file into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791143#M253360</link>
      <description>&lt;P&gt;Given your example show the expected output.&lt;/P&gt;
&lt;PRE&gt;File.fdf

-----------------------------------------------------------

askdjf;lk
fdasfe
qweiopqwur
&amp;lt;&amp;lt;/Contents(variable1)-akljsdfkj
Page 1&amp;gt;&amp;gt;&amp;lt;&amp;lt;xj/variable2-akljsdfkj Page 1&amp;gt;&amp;gt;&amp;lt;&amp;lt;/Contents(variable2) -akljsdfkj
Page 4&amp;gt;&amp;gt;4564324&amp;lt;&amp;lt;/Contents(variable2-akljsdfkj Page 2&amp;gt;&amp;gt;&amp;lt;&amp;lt;Contents(ar/variable1)-akljsdfkj
Page 3&amp;gt;&amp;gt;
&amp;lt;&amp;lt;/Contents(variable1) -akljsdfkj
Page 4&amp;gt;&amp;gt;

hjkasdfkjhsdfe

-------------------------------------------------------&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 14:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791143#M253360</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2022-01-20T14:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an .fdf file into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791148#M253361</link>
      <description>&lt;P&gt;Do you have a design document that describes the file format?&lt;/P&gt;
&lt;P&gt;It does not look like an Adobe Form Data File.&amp;nbsp;&amp;nbsp;&lt;A href="https://docs.appligent.com/fdfmerge/fdfmerge-form-data-format/" target="_blank"&gt;https://docs.appligent.com/fdfmerge/fdfmerge-form-data-format/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 14:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791148#M253361</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-20T14:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an .fdf file into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791154#M253363</link>
      <description>&lt;P&gt;That does not look like the right output for that input file.&amp;nbsp; One of the &amp;lt;&amp;lt;/Content( strings is missing the slash.&lt;/P&gt;
&lt;P&gt;First let's make an actual text file we can use as input.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options parmcards=fdf ;
filename fdf temp;
parmcards4;
askdjf;lk
fdasfe
qweiopqwur
&amp;lt;&amp;lt;/Contents(variable1)-akljsdfkj
Page 1&amp;gt;&amp;gt;&amp;lt;&amp;lt;xj/variable2-akljsdfkj Page 1&amp;gt;&amp;gt;&amp;lt;&amp;lt;/Contents(variable2) -akljsdfkj
Page 4&amp;gt;&amp;gt;4564324&amp;lt;&amp;lt;/Contents(variable2-akljsdfkj Page 2&amp;gt;&amp;gt;&amp;lt;&amp;lt;Contents(ar/variable1)-akljsdfkj
Page 3&amp;gt;&amp;gt;
&amp;lt;&amp;lt;/Contents(variable1) -akljsdfkj
Page 4&amp;gt;&amp;gt;

hjkasdfkjhsdfe
;;;;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's use the&amp;nbsp;@ command to find the starting points and the SCAN() function to remove the trailing letters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile fdf column=cc ;
  input @'&amp;lt;&amp;lt;/Contents(' variable :$200. @;
  variable=scan(variable,1,')');
  input @'Page ' @ ;
  s = cc ;
  input string :$20. @;
  Page = scan(string,1,'&amp;gt;') ;
  output;
  input @s @@;
  drop s string;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    variable               Page

 1     variable1               1
 2     variable2               4
 3     variable2-akljsdfkj     2
 4     variable1               4
&lt;/PRE&gt;
&lt;P&gt;If there are limits on what characters can be valid in the variable name then it could be even simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile fdf flowover dlm=')&amp;gt; ';
  input @'&amp;lt;&amp;lt;/Contents(' variable :$200. @'Page ' page @@ ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Jan 2022 14:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791154#M253363</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-20T14:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an .fdf file into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791156#M253364</link>
      <description>Hi Tom, thank you for reading my topic. The example data I provided was indeed just an abstraction of an old FDF file. It doesn't represent the exact file format. I basically have an export of comments from a PDF than I'm unable to provide at the moment. I will look a document describing the exact format.</description>
      <pubDate>Thu, 20 Jan 2022 14:27:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791156#M253364</guid>
      <dc:creator>LuisB</dc:creator>
      <dc:date>2022-01-20T14:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an .fdf file into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791157#M253365</link>
      <description>Added! thank you!</description>
      <pubDate>Thu, 20 Jan 2022 14:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791157#M253365</guid>
      <dc:creator>LuisB</dc:creator>
      <dc:date>2022-01-20T14:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an .fdf file into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791159#M253366</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi Tom, thank you for reading my topic. The example data I provided was indeed just an abstraction of an old FDF file. It doesn't represent the exact file format. I basically have an export of comments from a PDF than I'm unable to provide at the moment. I will look a document describing the exact format.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 14:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791159#M253366</guid>
      <dc:creator>LuisB</dc:creator>
      <dc:date>2022-01-20T14:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an .fdf file into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791164#M253368</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think this, combined with the LRECL option definitely solves my problem. I still don't fully understand why, though. Is the last&amp;nbsp;@@ the trigger to move to the next 'line'? Why is the input of the last 's' required even after you OUTPUT?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 14:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791164#M253368</guid>
      <dc:creator>LuisB</dc:creator>
      <dc:date>2022-01-20T14:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Reading an .fdf file into SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791169#M253369</link>
      <description>&lt;P&gt;The double trailing&amp;nbsp;@ holds the input pointer on the current line for the next iteration of the data step.&amp;nbsp; So you can find multiple /Contents tags on the same "line" of the file.&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;@S is to move the pointer back to where it started to read to string used to find the page number, just in case that read accidentally read past the start of the next /Contents tag.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 14:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-an-fdf-file-into-SAS/m-p/791169#M253369</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-20T14:54:42Z</dc:date>
    </item>
  </channel>
</rss>

