<?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 a data labels from a tab delimited .dat file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/758669#M239597</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a flat file of a large number of categorical variables and their labels that I need to import into SAS.&lt;/P&gt;&lt;P&gt;Sample lines:&lt;/P&gt;&lt;P&gt;Label&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Variable&amp;nbsp; &amp;nbsp;Type (categorical or numeric)&amp;nbsp; &amp;nbsp; &amp;nbsp;Category or value&lt;/P&gt;&lt;P&gt;Not reported&amp;nbsp; &amp;nbsp; Sex&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NR&lt;/P&gt;&lt;P&gt;Female&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sex&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;Male&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sex&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;&lt;P&gt;1:2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ratio&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;1:3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ratio&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The challenges seem to be that, even though the file is tab delimited, individual values are of:&lt;/P&gt;&lt;P&gt;- Variable length of labels, variable names, and category/value&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Some entries contain spaces&lt;/P&gt;&lt;P&gt;- Some entries contain : symbols&lt;/P&gt;&lt;P&gt;- Some lines are for categorical variables, some for numerical&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code as follows:&lt;/P&gt;&lt;P&gt;data format;&lt;BR /&gt;infile "H:\Working data\file.dat" delimiter='05'x;&lt;BR /&gt;input label &amp;amp; $ variable $ type $ value &amp;amp;;&lt;BR /&gt;run ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This has not worked, with the most consistent error message " SAS went to a new line when INPUT statement reached past the end of a line. Moreover, the values in the .sas dataset seem to be eliminating spaces.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two questions for the group:&lt;/P&gt;&lt;P&gt;- Is reading in the file even the right thing to do, if I only need it eventually to label individual variables?&lt;/P&gt;&lt;P&gt;- If I do need to import the file, how can I modify the code to ensure that the file is read in accurately?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much,&lt;/P&gt;&lt;P&gt;Emily&lt;/P&gt;</description>
    <pubDate>Sun, 01 Aug 2021 20:34:23 GMT</pubDate>
    <dc:creator>EmilyAV</dc:creator>
    <dc:date>2021-08-01T20:34:23Z</dc:date>
    <item>
      <title>Importing a data labels from a tab delimited .dat file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/758669#M239597</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a flat file of a large number of categorical variables and their labels that I need to import into SAS.&lt;/P&gt;&lt;P&gt;Sample lines:&lt;/P&gt;&lt;P&gt;Label&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Variable&amp;nbsp; &amp;nbsp;Type (categorical or numeric)&amp;nbsp; &amp;nbsp; &amp;nbsp;Category or value&lt;/P&gt;&lt;P&gt;Not reported&amp;nbsp; &amp;nbsp; Sex&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NR&lt;/P&gt;&lt;P&gt;Female&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sex&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;Male&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sex&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;&lt;P&gt;1:2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ratio&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;1:3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ratio&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The challenges seem to be that, even though the file is tab delimited, individual values are of:&lt;/P&gt;&lt;P&gt;- Variable length of labels, variable names, and category/value&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Some entries contain spaces&lt;/P&gt;&lt;P&gt;- Some entries contain : symbols&lt;/P&gt;&lt;P&gt;- Some lines are for categorical variables, some for numerical&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code as follows:&lt;/P&gt;&lt;P&gt;data format;&lt;BR /&gt;infile "H:\Working data\file.dat" delimiter='05'x;&lt;BR /&gt;input label &amp;amp; $ variable $ type $ value &amp;amp;;&lt;BR /&gt;run ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This has not worked, with the most consistent error message " SAS went to a new line when INPUT statement reached past the end of a line. Moreover, the values in the .sas dataset seem to be eliminating spaces.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two questions for the group:&lt;/P&gt;&lt;P&gt;- Is reading in the file even the right thing to do, if I only need it eventually to label individual variables?&lt;/P&gt;&lt;P&gt;- If I do need to import the file, how can I modify the code to ensure that the file is read in accurately?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much,&lt;/P&gt;&lt;P&gt;Emily&lt;/P&gt;</description>
      <pubDate>Sun, 01 Aug 2021 20:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/758669#M239597</guid>
      <dc:creator>EmilyAV</dc:creator>
      <dc:date>2021-08-01T20:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a data labels from a tab delimited .dat file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/758672#M239600</link>
      <description>&lt;P&gt;Tabs are '09'x, not '05'x.&lt;/P&gt;
&lt;P&gt;Define the variables with a proper length in a LENGTH statement before using them in the INPUT. After that, you do not need to use any attributes in INPUT.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Aug 2021 20:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/758672#M239600</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-01T20:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a data labels from a tab delimited .dat file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/758673#M239601</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 01 Aug 2021 21:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/758673#M239601</guid>
      <dc:creator>EmilyAV</dc:creator>
      <dc:date>2021-08-01T21:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a data labels from a tab delimited .dat file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/758675#M239602</link>
      <description>&lt;P&gt;Labels are attached to variables.&amp;nbsp; You can modify the way values are displayed by using a FORMAT.&amp;nbsp; So it looks like your file has format definitions, not variable labels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your posted file does not look like a delimited file.&amp;nbsp; It looks like someone has tried to align the text into columns.&amp;nbsp;If it does have tab character then perhaps it is because someone edited the file in a word processor that inserts tab characters to replace spaces?&amp;nbsp; &amp;nbsp;If it has tabs they should the '09'x on an ASCII based system, Only on EBCIDIC based systems (IBM mainframes) is '05'x a tab character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the EXPANDTABS option on the INFILE statement to have the tabs expanded to spaces using stops every 8 columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this code to read the file and generate the formats.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ctnlin ;
  infile "H:\Working data\file.dat" expandtabs truncover firstobs=2;
  length fmtname $32 type $1 start $40 label $200 ;
  input label fmtname type start ;
  if type='C' then fmtname='$' || fmtname;
  if andigit(char(fmtname,length(fmtname)) then fmtname=cats(fmtname,'F');
run;

proc format cntlin=cntlin fmtlib;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;----------------------------------------------------------------------------
|       FORMAT NAME: $RATIO   LENGTH:    3   NUMBER OF VALUES:    2        |
|   MIN LENGTH:   1  MAX LENGTH:  40  DEFAULT LENGTH:   3  FUZZ:        0  |
|--------------------------------------------------------------------------|
|START           |END             |LABEL  (VER. V7|V8   01AUG2021:17:34:15)|
|----------------+----------------+----------------------------------------|
|2               |2               |1:2                                     |
|3               |3               |1:3                                     |
----------------------------------------------------------------------------


----------------------------------------------------------------------------
|       FORMAT NAME: $SEX     LENGTH:   12   NUMBER OF VALUES:    3        |
|   MIN LENGTH:   1  MAX LENGTH:  40  DEFAULT LENGTH:  12  FUZZ:        0  |
|--------------------------------------------------------------------------|
|START           |END             |LABEL  (VER. V7|V8   01AUG2021:17:34:15)|
|----------------+----------------+----------------------------------------|
|F               |F               |Female                                  |
|M               |M               |Male                                    |
|NR              |NR              |Not reported                            |
----------------------------------------------------------------------------&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 15:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/758675#M239602</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-12T15:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a data labels from a tab delimited .dat file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/761163#M240804</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 14:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-data-labels-from-a-tab-delimited-dat-file/m-p/761163#M240804</guid>
      <dc:creator>EmilyAV</dc:creator>
      <dc:date>2021-08-12T14:43:35Z</dc:date>
    </item>
  </channel>
</rss>

