<?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: Import the files with variable length of observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807215#M318204</link>
    <description>Thank you, Tom.&lt;BR /&gt;Unfortunately, I don’t know all possible lines style that I can receive. But I need only the lines with Error.</description>
    <pubDate>Mon, 11 Apr 2022 17:49:43 GMT</pubDate>
    <dc:creator>SASdevAnneMarie</dc:creator>
    <dc:date>2022-04-11T17:49:43Z</dc:date>
    <item>
      <title>Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807067#M318105</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to import multiples files. My code is :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Mes_fichiers;

	data PDF_IN (keep=Mes_fichiers);
		length Mes_fichiers $256;
		fich=filename('fich',"&amp;amp;A.");
		did=dopen('fich');
		nb_fich=dnum(did);

		do i=1 TO nb_fich;
			Mes_fichiers=dread(did,i);
			output;
		end;

		rc=dclose(did);
	run;


	DATA _null_;
		call symputx ('nb', nobs);
		SET PDF_IN nobs=nobs;
	run;

	%do i=1 %to &amp;amp;nb.;

		data _NULL_;
			set PDF_IN(obs=&amp;amp;i);
			CALL SYMPUTX(COMPRESS('Mes_fichiers'),Mes_fichiers);
		run;

		data table_&amp;amp;i.;
			infile "&amp;amp;A.\&amp;amp;Mes_fichiers." dsd dlm="" missover firstobs=2;
			informat A $10.;
			informat B $28.;
			informat C $9.;
			informat D $8.;
			format A $10.;
			format B $28.;
			format C $9.;
			format D $8.;
			input A $1-10 B $12-39 C $40-48 D $49-56;
		run;

	%end;
%mend;

%Mes_fichiers;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code is works, but sometimes in my files (are joined) the length of observation is changing.&lt;/P&gt;
&lt;P&gt;Do you know, please, how to import the files with variable length of observation ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2022 19:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807067#M318105</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-04-10T19:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807076#M318111</link>
      <description>&lt;P&gt;What is it that you are having trouble with exactly?&lt;BR /&gt;Is it getting the right data step to consistently read files that look like the two examples you posted?&lt;/P&gt;
&lt;P&gt;What values do you want extract from the files?&amp;nbsp; They seem to mainly have three values per line, DATE, BANK_NAME and BANK_ID.&amp;nbsp; &amp;nbsp;The text seems to be constant.&amp;nbsp; Does the text actually vary?&amp;nbsp; Can you highlight some examples of the different texts that can appear?&lt;/P&gt;
&lt;P&gt;Let's take a few lines from your first example file and convert it into a temporary text file on our local SAS instance so we can try reading it.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename example1 temp;
options parmcards=example1;
parmcards4;
2022-03-10 Loaded banks from CSV file 228 Bank from CSV file /srv/thetys-almpower/data/masterDataInterface/work/20220310-235502/Banques_20220310.csv
2022-03-10 No update required for bank LSAF5055 id= 656
2022-03-10 No update required for bank BNCA1045 id= 468
2022-03-10 No update required for bank CMAG1047 id= 577
2022-03-10 No update required for bank MEES594 id= 600
2022-03-10 No update required for bank BCME1146 id= 514
2022-03-10 No update required for bank EURO2994 id= 594
;;;;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you could read that file pretty easily. Especially if you don't care about the text.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example1;
  length date 8 bank $20 id 8 sourcefile $100 ;
  infile example1 truncover ;
  input date yymmdd10. @ ;
  if _n_=1 then do;
    sourcefile = scan(_infile_,-1,' ');
    delete;
  end;
  else input @'bank' bank @'id=' id ;
  retain sourcefile;
  format date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs          date      bank       id                                          sourcefile

 1     2022-02-25    LSAF5055    656    /srv/thetys-almpower/data/masterDataInterface/work/20220225-235501/Banques_20220225.csv
 2     2022-02-25    BNCA1045    468    /srv/thetys-almpower/data/masterDataInterface/work/20220225-235501/Banques_20220225.csv
 3     2022-02-25    CMAG1047    577    /srv/thetys-almpower/data/masterDataInterface/work/20220225-235501/Banques_20220225.csv
 4     2022-02-25    MEES594     600    /srv/thetys-almpower/data/masterDataInterface/work/20220225-235501/Banques_20220225.csv
 5     2022-02-25    BCME1146    514    /srv/thetys-almpower/data/masterDataInterface/work/20220225-235501/Banques_20220225.csv
 6     2022-02-25    EURO2994    594    /srv/thetys-almpower/data/masterDataInterface/work/20220225-235501/Banques_20220225.csv
 7     2022-02-25    CACF3078    563    /srv/thetys-almpower/data/masterDataInterface/work/20220225-235501/Banques_20220225.csv
&lt;/PRE&gt;
&lt;P&gt;Or is it getting the list of files to read?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the rule for selecting the file names?&amp;nbsp; Do you just want to read all of the files?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 00:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807076#M318111</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-11T00:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807110#M318131</link>
      <description>Thank you for your answer, Tom.&lt;BR /&gt;I would like to extract the text with the word Error. Using my code it’s not correct.</description>
      <pubDate>Mon, 11 Apr 2022 08:08:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807110#M318131</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-04-11T08:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807112#M318133</link>
      <description>&lt;UL&gt;
&lt;LI&gt;Do not use tabs in code, replace them with a suitable number of blanks. Both SAS Studio and Enterprise Guide provide settings for this. Tabs are different on different systems and/or for different users, so the visual layout is undetermined when using tabs.&lt;/LI&gt;
&lt;LI&gt;Do not use FORMAT or INFORMAT statements to define variables, use a LENGTH statement instead. In most cases, character variables do not need formats/informats.&lt;/LI&gt;
&lt;LI&gt;Use a mixture of LIST and FORMATTED INPUT:&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_&amp;amp;i.;
infile "&amp;amp;A.\&amp;amp;Mes_fichiers." dsd dlm="" truncover firstobs=2;
length
  A $10
  B $28
  C $9
  D $8
;
input A @12 B $28. C D $8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since most of the input is static, you may want to consider not reading four variables, but parsing the date, bank and id from _INFILE_.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 08:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807112#M318133</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-11T08:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807113#M318134</link>
      <description>&lt;P&gt;I see you have differently structured lines farther down. Read the date (is there in every line) with yymmdd10. and the rest of the line into a long variable (formatted input, don't forget TRUNCOVER), which you then parse dependent on the first word(s).&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 08:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807113#M318134</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-11T08:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807213#M318202</link>
      <description>Thank you, Kurt!&lt;BR /&gt;Do you mean that I must write B $300? I would like to get only the line with the word Error.Where do I need to add truncover? Thank you for the help.</description>
      <pubDate>Mon, 11 Apr 2022 17:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807213#M318202</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-04-11T17:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807214#M318203</link>
      <description>&lt;P&gt;Reading the lines from the file is simple.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'myfile.txt' truncover ;
  input date :yymmdd. ;
  format date yymmdd10.;
  length line $300 ;
  line=_infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To get help with doing more please clarify what all of the possible lines styles are and what you want to extract out of them.&lt;/P&gt;
&lt;P&gt;For example you might want to only keep the lines that have the word ERROR in them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'myfile.txt' truncover ;
  input date :yymmdd. ;
  format date yymmdd10.;
  length line $300 ;
  line=_infile_;
  if findw(line,'error','i') ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2022 17:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807214#M318203</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-11T17:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807215#M318204</link>
      <description>Thank you, Tom.&lt;BR /&gt;Unfortunately, I don’t know all possible lines style that I can receive. But I need only the lines with Error.</description>
      <pubDate>Mon, 11 Apr 2022 17:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807215#M318204</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-04-11T17:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807217#M318206</link>
      <description>&lt;P&gt;Once you have the text into data you can easily explore it.&lt;/P&gt;
&lt;P&gt;For example if skip the DATE value when reading the line:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'myfile.txt' truncover ;
  input date :yymmdd. line $300.;
  format date yymmdd10.;
  if findw(line,'error','i');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could use a short display format with PROC FREQ to get a look at the most common starting values of the strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq order=freq data=want;
   tables line / list;
   format line $30.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2022 17:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807217#M318206</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-11T17:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807247#M318225</link>
      <description>Thank you, Tom !&lt;BR /&gt;Unfortunately the condtion :     if findw(line,'error ','i') doesn't work, I have the empty tables&lt;BR /&gt;(when I apply the filter of SASEG I have the "error") but I can apply prxmatch function lately on my data.</description>
      <pubDate>Mon, 11 Apr 2022 20:35:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807247#M318225</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-04-11T20:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Import the files with variable length of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807290#M318256</link>
      <description>&lt;P&gt;Read your file like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testfile1;
infile "~/testfile1.txt" truncover;
input date :yymmdd10. line $300.;
format date yymmdd10.;
if index(upcase(line),"ERROR");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Tested on On Demand after uploading your test file.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 06:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-the-files-with-variable-length-of-observations/m-p/807290#M318256</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-12T06:58:01Z</dc:date>
    </item>
  </channel>
</rss>

