<?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 .cvs date into SAS issue in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9157#M564</link>
    <description>Thanks Scott, can you advise how to fix it the the code?&lt;BR /&gt;
&lt;BR /&gt;
Thank you again!</description>
    <pubDate>Mon, 23 Mar 2009 00:19:32 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-03-23T00:19:32Z</dc:date>
    <item>
      <title>Import .cvs date into SAS issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9151#M558</link>
      <description>Hi Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
I can't import the date from cvs file into SAS data, here is the code:&lt;BR /&gt;
&lt;BR /&gt;
data abc;&lt;BR /&gt;
    infile "/home/path/time.csv" delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;&lt;BR /&gt;
    informat id $1.;&lt;BR /&gt;
    informat type $1.;&lt;BR /&gt;
    informat cls_dt mmddyy10.;&lt;BR /&gt;
    format id $1.;&lt;BR /&gt;
    format type $1.;&lt;BR /&gt;
    format cls_dt mmddyy10.;&lt;BR /&gt;
    input id $&lt;BR /&gt;
            type $&lt;BR /&gt;
            cls_dt&lt;BR /&gt;
          ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
The error reads invalid data for cls_dt.&lt;BR /&gt;
&lt;BR /&gt;
Can you help me with the issue?</description>
      <pubDate>Sat, 21 Mar 2009 05:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9151#M558</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-21T05:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Import .cvs date into SAS issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9152#M559</link>
      <description>Do consider that you are posting to a general forum, although Cynthia is quite an incredible individual with her time and effort and dedication to tracking posts, replies and the like.&lt;BR /&gt;
&lt;BR /&gt;
Please provide some additional diagnostic information, please, such as adding a command:&lt;BR /&gt;
&lt;BR /&gt;
IF _N_ LE 5 THEN PUTLOG '&amp;gt;DIAG&amp;gt;' _ALL_ / _INFILE_;&lt;BR /&gt;
&lt;BR /&gt;
which will dump your input record to the SASLOG for the first 5 input records.&lt;BR /&gt;
&lt;BR /&gt;
But first, consider:  from the diagnostic message, can you confirm that your "date field" is in the expected input format, as you have defined with the INFORMAT statement?&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sat, 21 Mar 2009 20:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9152#M559</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-21T20:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import .cvs date into SAS issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9153#M560</link>
      <description>Thank you so much Scott!&lt;BR /&gt;
&lt;BR /&gt;
Here is my question in a general sense:when I use infile-informat-format-input to import csv files, if the last variable is numeric,it can not be loaded in,error message reads invalid data for variable. But if I add a character variable to the original csv file,immediately following the numeric variable(now the character variable becomes the last column),the numeric variable can be loaded as needed.&lt;BR /&gt;
&lt;BR /&gt;
I really got confused at this, and want to figure out why and how to resolve this problem, as I assume it can be a common issue that many can encounter.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again for the kind help here!</description>
      <pubDate>Sun, 22 Mar 2009 02:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9153#M560</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-22T02:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Import .cvs date into SAS issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9154#M561</link>
      <description>Hi:&lt;BR /&gt;
  It would be better if you could post some of your data, but there are some general things to check for. Consider this "test" data:&lt;BR /&gt;
[pre]&lt;BR /&gt;
"id","type","cls_dt"&lt;BR /&gt;
1,a,11/15/1950&lt;BR /&gt;
2,b,08/23/1951&lt;BR /&gt;
3,c,23/8/1951&lt;BR /&gt;
4,d,11/29/1984&lt;BR /&gt;
5,e,21Mar2009&lt;BR /&gt;
6,03/21/2009,f&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
There's something wrong with ID #3 (the date is NOT MM/DD/YYYY form). Neither is the date for ID #5. Both of those dates are in the wrong form. For ID #6, there's a different problem -- the variable values were entered in the CSV file with CLS_DT and TYPE reversed on the row.&lt;BR /&gt;
 &lt;BR /&gt;
What's going to happen when SAS tries to read this file? Some of the input records will be OK. Some of the input records will generate an error. Here's the LOG that results from trying to read the above file:&lt;BR /&gt;
[pre]&lt;BR /&gt;
136  data abc;&lt;BR /&gt;
137  infile datalines delimiter = ',' MISSOVER DSD firstobs=2 ;&lt;BR /&gt;
138  informat id $1.type $1. cls_dt mmddyy10.;&lt;BR /&gt;
139  format id $1. type $1.cls_dt mmddyy10.;&lt;BR /&gt;
140  input id $ type $ cls_dt ;&lt;BR /&gt;
141  return;&lt;BR /&gt;
142  datalines;&lt;BR /&gt;
                            &lt;BR /&gt;
NOTE: Invalid data for cls_dt in line 146 5-13.&lt;BR /&gt;
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+&lt;BR /&gt;
146        3,c,23/8/1951&lt;BR /&gt;
id=3 type=c cls_dt=. _ERROR_=1 _N_=3&lt;BR /&gt;
NOTE: Invalid data for cls_dt in line 148 5-13.&lt;BR /&gt;
148        5,e,21Mar2009&lt;BR /&gt;
id=5 type=e cls_dt=. _ERROR_=1 _N_=5&lt;BR /&gt;
NOTE: Invalid data for cls_dt in line 149 14-14.&lt;BR /&gt;
149        6,03/21/2009,f&lt;BR /&gt;
id=6 type=0 cls_dt=. _ERROR_=1 _N_=6&lt;BR /&gt;
NOTE: The data set WORK.ABC has 6 observations and 3 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
              &lt;BR /&gt;
              &lt;BR /&gt;
150  ;&lt;BR /&gt;
151  run;&lt;BR /&gt;
                                              &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                        &lt;BR /&gt;
You can see that I got exactly the same error message as you reported, for the rows in the data, where there was something wrong with CLS_DT. One good diagnostic technique is to visually examine your file, SAS will only report the first 20 or so errors, but you may be able to find out, by examining the log just which rows have the problem.&lt;BR /&gt;
                                 &lt;BR /&gt;
To fix records #3 and #5, I could go to the CSV file and re-type them to be MMDDYY format and then resave the CSV file. To fix record #6, the entire line needs to be fixed so that TYPE is where SAS expects it and CLS_DT comes after TYPE on the line.&lt;BR /&gt;
                                              &lt;BR /&gt;
Another way to read all the different date values would be to use the ANYDTDTE informat instead of the MMDDYY10. informat. However, nothing will help you "fix" bad record #6.&lt;BR /&gt;
                                              &lt;BR /&gt;
An INFORMAT statement tells SAS how to read records INTO SAS format. So, if your data does not correspond to the INFORMAT you specify, SAS has no choice but to issue an error message. The FORMAT statement tells SAS how to display SAS values when they're used by procedures, such as PROC PRINT or PROC FREQ or PROC MEANS, etc, etc. So, for example, the first date on ID #1 is 11/15/1950. This date is "internally" stored in the SAS dataset as -3334, the number of days from Jan 1, 1960. If you wanted to display that value with different DATE formats, that date value can be "formatted" a number of different ways:&lt;BR /&gt;
15Nov1950  Date9.&lt;BR /&gt;
11/15/1950 mmddyy10.&lt;BR /&gt;
11/15/50    mmddyy8.&lt;BR /&gt;
1950-11-15 yymmdd10.&lt;BR /&gt;
November 15, 1950 worddate.&lt;BR /&gt;
 &lt;BR /&gt;
On the other hand, your program can only specify one method for how data should be read INTO SAS using an INFORMAT. I suspect the reason you're getting that error is that you have some bad data rows or records in the CSV file.  It's entirely possible that not all the CLS_DT variables use the MMDDYY10. INFORMAT for the values.&lt;BR /&gt;
  &lt;BR /&gt;
Scott showed you a good debugging technique. You might read in the documentation about INFORMATs and FORMATs and "cleaning" data. If you cannot edit the data yourself, then you may only be able to report the errors to the people who maintain the file and ask them to do corrections and then send you a corrected file. &lt;BR /&gt;
 &lt;BR /&gt;
Good luck!&lt;BR /&gt;
cynthia</description>
      <pubDate>Sun, 22 Mar 2009 02:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9154#M561</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-03-22T02:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: Import .cvs date into SAS issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9155#M562</link>
      <description>Thanks a lot Cynthia.&lt;BR /&gt;
&lt;BR /&gt;
Here is my code:&lt;BR /&gt;
&lt;BR /&gt;
data abc;&lt;BR /&gt;
infile "/home/path/time.csv" delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;&lt;BR /&gt;
informat id $1.type $1. time mmddyy10.;&lt;BR /&gt;
format id $1. type $1. time mmddyy10.;&lt;BR /&gt;
input id $ type $ time&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
The data time.csv file are as the follow:&lt;BR /&gt;
&lt;BR /&gt;
id,type,time&lt;BR /&gt;
1,a,12/20/2008&lt;BR /&gt;
2,a,12/21/2008&lt;BR /&gt;
3,s,12/22/2008&lt;BR /&gt;
4,d,12/23/2008&lt;BR /&gt;
&lt;BR /&gt;
Here is the error:&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Invalid data for time in line 2 5-15.&lt;BR /&gt;
RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                      &lt;BR /&gt;
&lt;BR /&gt;
2   CHAR  1,a,12/20/2008. 15&lt;BR /&gt;
    ZONE  326233233233330&lt;BR /&gt;
    NUMR  1C1C12F20F2008D&lt;BR /&gt;
id=1 type=a time=. _ERROR_=1 _N_=1&lt;BR /&gt;
NOTE: Invalid data for time in line 3 5-15.&lt;BR /&gt;
&lt;BR /&gt;
3   CHAR  2,a,12/21/2008. 15&lt;BR /&gt;
    ZONE  326233233233330&lt;BR /&gt;
    NUMR  2C1C12F21F2008D&lt;BR /&gt;
id=2 type=a time=. _ERROR_=1 _N_=2&lt;BR /&gt;
NOTE: Invalid data for time in line 4 5-15.&lt;BR /&gt;
&lt;BR /&gt;
4   CHAR  3,s,12/22/2008. 15&lt;BR /&gt;
    ZONE  327233233233330&lt;BR /&gt;
    NUMR  3C3C12F22F2008D&lt;BR /&gt;
id=3 type=s time=. _ERROR_=1 _N_=3&lt;BR /&gt;
NOTE: Invalid data for time in line 5 5-15.&lt;BR /&gt;
&lt;BR /&gt;
5   CHAR  4,d,12/23/2008. 15&lt;BR /&gt;
    ZONE  326233233233330&lt;BR /&gt;
    NUMR  4C4C12F23F2008D&lt;BR /&gt;
id=4 type=d time=. _ERROR_=1 _N_=4&lt;BR /&gt;
NOTE: 4 records were read from the infile "/home/path/time.csv".&lt;BR /&gt;
&lt;BR /&gt;
The problem still exists. If I copy the data and paste in the code after datalines,it works. But in practice, there are too many rows that I can't use datalines but need use infile from the .csv file, it results in error. &lt;BR /&gt;
&lt;BR /&gt;
If I add one more character column after the time variable in the time.csv file, it works too,that is what I mean "the last variable is a numeric variable".&lt;BR /&gt;
&lt;BR /&gt;
I checked all date values are in the right form,no bad data here, you can also see in the small data sample in the code above.&lt;BR /&gt;
&lt;BR /&gt;
Can you help figure out what has led to the error?&lt;BR /&gt;
&lt;BR /&gt;
Thanks again for your kind help!</description>
      <pubDate>Sun, 22 Mar 2009 19:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9155#M562</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-22T19:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Import .cvs date into SAS issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9156#M563</link>
      <description>Your input data shows a trailing period character (note the SAS diagnostic mentions column 5-15).  The problem is in your input data, not having the expected delimiter character or an end-of-record condition.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 22 Mar 2009 22:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9156#M563</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-22T22:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Import .cvs date into SAS issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9157#M564</link>
      <description>Thanks Scott, can you advise how to fix it the the code?&lt;BR /&gt;
&lt;BR /&gt;
Thank you again!</description>
      <pubDate>Mon, 23 Mar 2009 00:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9157#M564</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-23T00:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Import .cvs date into SAS issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9158#M565</link>
      <description>&amp;gt; Your input data shows a trailing period character&lt;BR /&gt;
&amp;gt; (note the SAS diagnostic mentions column 5-15).  &lt;BR /&gt;
Not a period, only displayed as period by in the CHAR portion of the implied LIST statement output.  ZONE NUMR is a vertical HEX display of each character which reveals the value as '0D'x.  An end of line character on some OSs&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
 RULE: ----+----1----+----2----+---&lt;BR /&gt;
2 CHAR 1,a,12/20/2008. 15&lt;BR /&gt;
  ZONE 326233233233330&lt;BR /&gt;
  NUMR 1C1C12F20F2008D&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
This implies the file was created on Windows and is being read with UNIX.  Unix uses a single character '0A'x as the end of record marker not '0D0A'x as is Windows.  SAS provides a way to fix it TERMSTR&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt;The problem is in your input data, not having the&lt;BR /&gt;
&amp;gt; expected delimiter character or an end-of-record&lt;BR /&gt;
&amp;gt; condition.&lt;BR /&gt;
&lt;BR /&gt;
This statement is correct and using TERMSTR should make it all good.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Beginning in SAS 9, the INFILE statement TERMSTR= option specifies the&lt;BR /&gt;
end-of-line character for the specified file.  Use this option to read&lt;BR /&gt;
files created on UNIX in a SAS session on Windows, and vice versa.&lt;BR /&gt;
Valid TERMSTR= values are:&lt;BR /&gt;
&lt;BR /&gt;
  CRLF (carriage return line feed) - use TERMSTR=CRLF to&lt;BR /&gt;
       read Windows formatted files.  CRLF is the default.&lt;BR /&gt;
&lt;BR /&gt;
  LF (line feed) - use TERMSTR=LF to read UNIX formatted files.&lt;BR /&gt;
&lt;BR /&gt;
  NL (new line) - Use TERMSTR=NL to read UNIX formatted files.&lt;BR /&gt;
[pre]</description>
      <pubDate>Mon, 23 Mar 2009 00:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9158#M565</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-23T00:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import .cvs date into SAS issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9159#M566</link>
      <description>Thanks to data _null_;  for info about the TERMSTR= option -- I was unfamiliar with using it.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
Scott</description>
      <pubDate>Mon, 23 Mar 2009 01:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9159#M566</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-23T01:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Import .cvs date into SAS issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9160#M567</link>
      <description>It works now with TERMSTR=CRLF!&lt;BR /&gt;
&lt;BR /&gt;
Thanks so much data_null, and Scott and Cynthia. I benefit so much here on this weekend, hope you guys all the best!</description>
      <pubDate>Mon, 23 Mar 2009 02:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Import-cvs-date-into-SAS-issue/m-p/9160#M567</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-23T02:20:39Z</dc:date>
    </item>
  </channel>
</rss>

