BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

UPDATED:

The text you posted that I copied had an string that could not be a date, that is why the code below worked.

 

You should report this to SAS as a BUG.

https://support.sas.com/en/technical-support/submit-a-support-request.html 

 

 

Spoiler

 

That seems wrong.  I cannot re-create the issue you are seeing. 

What version of SAS are you using?

Is there something else going on with that file?

 

This works on SAS 9.4M5 and the 9.4m6 version available in SAS ODA.

filename csv temp;
data _null_;
  file csv;
  put 'date'/'1989'/'22/14/2011';
run;
proc import dbms=csv file=csv out=want replace;
run;

proc print;
run;
36   /**********************************************************************
637   *   PRODUCT:   SAS
638   *   VERSION:   9.4
639   *   CREATOR:   External File Interface
640   *   DATE:      17AUG22
641   *   DESC:      Generated SAS Datastep Code
642   *   TEMPLATE SOURCE:  (None Specified.)
643   ***********************************************************************/
644      data WORK.WANT    ;
645      %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
646      infile CSV delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
647         informat date $10. ;
648         format date $10. ;
649      input
650                  date  $
651      ;
652      if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
653      run;

Tom_0-1660757756002.png

 

 

Tom
Super User Tom
Super User

Note that %CSV2DS() has no trouble with that specific example;

filename csv temp;
data _null_;
  file csv;
  put 'text,start,end'
    / 'abc,1968,1989'
    / 'def,2/14/2011,1981'
  ;
run;
proc import dbms=csv file=csv out=want replace;
run;

proc print;
run;

filename csv2ds url 'https://raw.githubusercontent.com/sasutils/macros/master/csv2ds.sas';
filename parmv url 'https://raw.githubusercontent.com/sasutils/macros/master/parmv.sas';
%include parmv;
%include csv2ds;

%csv2ds(csv);
proc print;
run;

Log

...
NOTE: Unable to open parameter catalog: SASUSER.PARMS.PARMS.SLIST in update mode. Temporary parameter values will be saved to 
 WORK.PARMS.PARMS.SLIST.
 79          /**********************************************************************
 80          *   PRODUCT:   SAS
 81          *   VERSION:   9.4
 82          *   CREATOR:   External File Interface
 83          *   DATE:      17AUG22
 84          *   DESC:      Generated SAS Datastep Code
 85          *   TEMPLATE SOURCE:  (None Specified.)
 86          ***********************************************************************/
 87             data WORK.WANT    ;
 88             %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
 89             infile CSV delimiter = ',' MISSOVER DSD  firstobs=2 ;
 90                informat text $3. ;
 91                informat start mmddyy10. ;
 92                informat end best32. ;
 93                format text $3. ;
 94                format start mmddyy10. ;
 95                format end best12. ;
 96             input
 97                         text  $
 98                         start
 99                         end
 100            ;
 101            if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
 102            run;
 
 NOTE: The infile CSV is:
       Filename=.../#LN00099,
       Owner Name=xxx,Group Name=oda,
       Access Permission=-rw-r--r--,
       Last Modified=17Aug2022:15:38:15,
       File Size (bytes)=48
 
 NOTE: Invalid data for start in line 2 5-8.
 RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                      
 2         abc,1968,1989 13
 text=abc start=. end=1989 _ERROR_=1 _N_=1
 NOTE: 2 records were read from the infile CSV.
       The minimum record length was 13.
       The maximum record length was 18.
 NOTE: The data set WORK.WANT has 2 observations and 3 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
...
 953       +data fromcsv;
 954       +  infile CSV dlm=',' dsd truncover firstobs=2 ;
 955       +  length text $3 start $9 end 8 ;
 956       +  input text -- end ;
 957       +run;
 
 NOTE: The infile CSV is:
       Filename=../#LN00099,
       Owner Name=xxx,Group Name=oda,
       Access Permission=-rw-r--r--,
       Last Modified=17Aug2022:15:38:15,
       File Size (bytes)=48
 
 NOTE: 2 records were read from the infile CSV.
       The minimum record length was 13.
       The maximum record length was 18.
 NOTE: The data set WORK.FROMCSV has 2 observations and 3 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds

Results

Tom_1-1660765269339.png

 

GerbenRotman
Calcite | Level 5
oh, yes, where I wrote "22/14/2011" that should have been "2/14/2011'...
Thanks, I have reported it as a bug.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 4111 views
  • 1 like
  • 4 in conversation