<?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 txt: variable width in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/import-txt-variable-width/m-p/887257#M350550</link>
    <description>&lt;P&gt;Have a look at the code below. If you want to execute you need to place a path that works for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path = your_folder_path;

proc export data = sashelp.cars(keep = drivetrain make model origin type)
         outfile = "&amp;amp;path.class.txt"
            dbms = dlm replace;
   delimiter=';';
run;
 
/*Syntax1*/
proc import datafile = "&amp;amp;path.class.txt"
                 out = cars1
	        replace;
   GETNAMES = yes;
   DELIMITER = ';';
run;

/*Syntax2*/
data cars2;    
   length drivetrain $100 make $100 model $100 origin $100 type $100;
   infile "&amp;amp;path.class.txt" dsd dlm = ";";
   input make model type origin drivetrain;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 01 Aug 2023 09:13:52 GMT</pubDate>
    <dc:creator>JosvanderVelden</dc:creator>
    <dc:date>2023-08-01T09:13:52Z</dc:date>
    <item>
      <title>import txt: variable width</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-variable-width/m-p/887250#M350549</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to import a text-file that has 5 variables (gs, zbz, regs, rpara, wertn). Result with the &lt;STRONG&gt;Syntax1&lt;/STRONG&gt;: Its importing the variables, but their content was cut off. Its strange, because I thought, thats not possible with &lt;CODE class=" language-sas"&gt;DELIMITER=';'.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Do you know how to fix that?&lt;STRONG&gt; Thank you!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;(The result of syntax2: SAs imports 5 variables, but without content)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;Sntax1:&lt;/STRONG&gt;&lt;BR /&gt;proc import datafile="[...].txt"
out=rkf
	 replace;
GETNAMES=yes;
DELIMITER=';';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;Syntax2:&lt;/STRONG&gt;&lt;BR /&gt;data want;
infile "[...].txt" 
	dlm=";" dsd truncover;
input
gs $100
zbz $100
regs $100
Rpara $100
wertn $100;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Aug 2023 08:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-variable-width/m-p/887250#M350549</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2023-08-01T08:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: import txt: variable width</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-variable-width/m-p/887257#M350550</link>
      <description>&lt;P&gt;Have a look at the code below. If you want to execute you need to place a path that works for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path = your_folder_path;

proc export data = sashelp.cars(keep = drivetrain make model origin type)
         outfile = "&amp;amp;path.class.txt"
            dbms = dlm replace;
   delimiter=';';
run;
 
/*Syntax1*/
proc import datafile = "&amp;amp;path.class.txt"
                 out = cars1
	        replace;
   GETNAMES = yes;
   DELIMITER = ';';
run;

/*Syntax2*/
data cars2;    
   length drivetrain $100 make $100 model $100 origin $100 type $100;
   infile "&amp;amp;path.class.txt" dsd dlm = ";";
   input make model type origin drivetrain;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Aug 2023 09:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-variable-width/m-p/887257#M350550</guid>
      <dc:creator>JosvanderVelden</dc:creator>
      <dc:date>2023-08-01T09:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: import txt: variable width</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-txt-variable-width/m-p/887324#M350580</link>
      <description>&lt;P&gt;In the INFILE statement you told SAS to use a semicolon as the delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the INPUT statement you told SAS to read the one byte in column 100 into each of the variables by using &lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.1/lestmtsref/n13ejk9swz5vrbn0z34iazfrp0wp.htm" target="_self"&gt;COLUMN MODE&lt;/A&gt; input, which will ignore the delimiter setting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the intent was to use the $100. informat then you need to include the period.&amp;nbsp; But that will not work either because when you use&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.1/lestmtsref/p0f9yk6pd4znukn1rlw6hzkg1url.htm" target="_self"&gt;FORMATTED MODE&lt;/A&gt; input the delimiter setting not have any effect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to use &lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.1/lestmtsref/n0lrz3gb7m9e4rn137op544ddg0v.htm" target="_self"&gt;LIST MODE&lt;/A&gt; input to read a delimited file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either define the variables first so you don't need the informats in the INPUT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length
  gs $100
  zbz $100
  regs $100
  Rpara $100
  wertn $100
;
input gs -- wertn ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if you want to use an informat in the INPUT statement so that SAS can GUESS you want to define the variable to store more than 8 bytes then use the colon modifier before the informat.&amp;nbsp; That will let INPUT know to use LIST MODE input instead of FORMATTED MODE input.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input
  gs :$100.
  zbz :$100.
  regs :$100.
  Rpara :$100.
  wertn :$100.
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 14:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-txt-variable-width/m-p/887324#M350580</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-01T14:50:26Z</dc:date>
    </item>
  </channel>
</rss>

