<?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: How can I read data with header from the file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73953#M15958</link>
    <description>Use the data import wizard in SAS EG - it generates the code for you.</description>
    <pubDate>Thu, 01 Oct 2009 08:25:51 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2009-10-01T08:25:51Z</dc:date>
    <item>
      <title>How can I read data with header from the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73952#M15957</link>
      <description>Hi, I am new to SAS datastep. I found trouble when reading data from a file. &lt;BR /&gt;
&lt;BR /&gt;
If data formated in the file looks like the following:&lt;BR /&gt;
&lt;BR /&gt;
 OBS     CITY                TMR         SMIN      SMEAN &lt;BR /&gt;
  1          PROVIDEN       1096         30          163         &lt;BR /&gt;
  2          JACKSON         789          29           70         &lt;BR /&gt;
  3          JOHNSTOW      1072        88           123       &lt;BR /&gt;
&lt;BR /&gt;
How can I read directly from the file and form a database in SAS?&lt;BR /&gt;
&lt;BR /&gt;
Without the column header, I know the statement might be:&lt;BR /&gt;
infile "xxx";&lt;BR /&gt;
input obs city $ tmr smin smean;&lt;BR /&gt;
&lt;BR /&gt;
However, how can I skip the first line of the file when reading data? or is it possible to directly take the column header as the variables?&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your help in advance.</description>
      <pubDate>Thu, 01 Oct 2009 08:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73952#M15957</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-01T08:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read data with header from the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73953#M15958</link>
      <description>Use the data import wizard in SAS EG - it generates the code for you.</description>
      <pubDate>Thu, 01 Oct 2009 08:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73953#M15958</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-10-01T08:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read data with header from the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73954#M15959</link>
      <description>You can skip the first line by using firstobs option in the infile statement:&lt;BR /&gt;
&lt;BR /&gt;
infile 'xxx' firstobs=2;</description>
      <pubDate>Thu, 01 Oct 2009 08:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73954#M15959</guid>
      <dc:creator>Oleg_L</dc:creator>
      <dc:date>2009-10-01T08:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read data with header from the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73955#M15960</link>
      <description>Thanks. I could do it.</description>
      <pubDate>Thu, 01 Oct 2009 14:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73955#M15960</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-01T14:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read data with header from the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73956#M15961</link>
      <description>&amp;gt; or is it possible to directly take&lt;BR /&gt;
&amp;gt; the column header as the variables?&lt;BR /&gt;
&lt;BR /&gt;
Here is one way.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
filename FT15F001 temp;&lt;BR /&gt;
proc import datafile=FT15F001 dbms=dlm out=test replace;&lt;BR /&gt;
   delimeter = ' ';&lt;BR /&gt;
   parmacrds;&lt;BR /&gt;
OBS CITY TMR SMIN SMEAN &lt;BR /&gt;
1 PROVIDEN 1096 30 163 &lt;BR /&gt;
2 JACKSON 789 29 70 &lt;BR /&gt;
3 JOHNSTOW 1072 88 123 &lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 01 Oct 2009 15:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73956#M15961</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-10-01T15:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read data with header from the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73957#M15962</link>
      <description>interesting demo! &lt;BR /&gt;
Is there some interaction between unit 15 (ft15f001) on TEMP and PARMCARDS?</description>
      <pubDate>Sat, 03 Oct 2009 15:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73957#M15962</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-10-03T15:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read data with header from the file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73958#M15963</link>
      <description>&amp;gt; interesting demo! &lt;BR /&gt;
&amp;gt; Is there some interaction between unit 15 (ft15f001)&lt;BR /&gt;
&amp;gt; on TEMP and PARMCARDS?&lt;BR /&gt;
&lt;BR /&gt;
I need to learn to spell and read the log.&lt;BR /&gt;
&lt;BR /&gt;
FT15F001 is the default fileref for PARMCARDS&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
47   proc options option=parmcards value define;&lt;BR /&gt;
48      run;&lt;BR /&gt;
&lt;BR /&gt;
    SAS (r) Proprietary Software Release 9.1  TS1M3&lt;BR /&gt;
&lt;BR /&gt;
Option Value Information For SAS Option PARMCARDS&lt;BR /&gt;
    Option Value: FT15F001&lt;BR /&gt;
    Option Scope: Default&lt;BR /&gt;
    How option value set:  Shipped Default&lt;BR /&gt;
Option Definition Information for SAS Option PARMCARDS&lt;BR /&gt;
    Group= ENVFILES&lt;BR /&gt;
    Group Description: SAS library and file location information&lt;BR /&gt;
    Description: Fileref for the PARMCARDS file&lt;BR /&gt;
    Type: The option value is of type CHARACTER&lt;BR /&gt;
          Maximum Number of Characters: 2048&lt;BR /&gt;
          Casing: The option value is retained with original casing.&lt;BR /&gt;
          Quotes: If present during "set", start and end quotes are removed&lt;BR /&gt;
          Parentheses: The option value does not require enclosure within parentheses. If present, the parentheses are&lt;BR /&gt;
          retained.&lt;BR /&gt;
          Expansion: Environment variables are not shown in expanded form.&lt;BR /&gt;
    When Can Set: Startup or anytime during the SAS Session&lt;BR /&gt;
    Restricted: Your Site Administrator can restrict modification of this option.&lt;BR /&gt;
    Optsave: Proc Optsave or command Dmoptsave will save this option.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
You don't have to use a temp file and if you just use PARMCARDS without defining FT15F001 you will get a file named FT15F001.DAT in the default directory.  &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
50   proc import datafile=FT15F001 dbms=dlm out=test replace;&lt;BR /&gt;
51      delimiter = ' ';&lt;BR /&gt;
52      parmcards;&lt;BR /&gt;
53   OBS CITY TMR SMIN SMEAN&lt;BR /&gt;
54   1 PROVIDEN 1096 30 163&lt;BR /&gt;
55   2 JACKSON 789 29 70&lt;BR /&gt;
56   3 JOHNSTOW 1072 88 123&lt;BR /&gt;
57   ;;;;&lt;BR /&gt;
&lt;BR /&gt;
58    /**********************************************************************&lt;BR /&gt;
59    *   PRODUCT:   SAS&lt;BR /&gt;
60    *   VERSION:   9.1&lt;BR /&gt;
61    *   CREATOR:   External File Interface&lt;BR /&gt;
62    *   DATE:      03OCT09&lt;BR /&gt;
63    *   DESC:      Generated SAS Datastep Code&lt;BR /&gt;
64    *   TEMPLATE SOURCE:  (None Specified.)&lt;BR /&gt;
65    ***********************************************************************/&lt;BR /&gt;
66       data TEST                                        ;&lt;BR /&gt;
67       %let _EFIERR_ = 0; /* set the ERROR detection macro variable */&lt;BR /&gt;
68       infile FT15F001 delimiter = ' ' MISSOVER DSD  firstobs=2 ;&lt;BR /&gt;
69          informat OBS best32. ;&lt;BR /&gt;
70          informat CITY $8. ;&lt;BR /&gt;
71          informat TMR best32. ;&lt;BR /&gt;
72          informat SMIN best32. ;&lt;BR /&gt;
73          informat SMEAN best32. ;&lt;BR /&gt;
74          format OBS best12. ;&lt;BR /&gt;
75          format CITY $8. ;&lt;BR /&gt;
76          format TMR best12. ;&lt;BR /&gt;
77          format SMIN best12. ;&lt;BR /&gt;
78          format SMEAN best12. ;&lt;BR /&gt;
79       input&lt;BR /&gt;
80                   OBS&lt;BR /&gt;
81                   CITY $&lt;BR /&gt;
82                   TMR&lt;BR /&gt;
83                   SMIN&lt;BR /&gt;
84                   SMEAN&lt;BR /&gt;
85       ;&lt;BR /&gt;
86       if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */&lt;BR /&gt;
87       run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The infile FT15F001 is:&lt;BR /&gt;
      File Name=C:\Documents and Settings\"data _null_"\My Documents\My SAS Files\9.1\FT15F001.DAT,&lt;BR /&gt;
      RECFM=V,LRECL=256&lt;BR /&gt;
&lt;BR /&gt;
NOTE: 3 records were read from the infile FT15F001.&lt;BR /&gt;
      The minimum record length was 19.&lt;BR /&gt;
      The maximum record length was 22.&lt;BR /&gt;
NOTE: The data set WORK.TEST has 3 observations and 5 variables.&lt;BR /&gt;
[/pre]</description>
      <pubDate>Sat, 03 Oct 2009 20:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-read-data-with-header-from-the-file/m-p/73958#M15963</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-10-03T20:36:06Z</dc:date>
    </item>
  </channel>
</rss>

