Limonade
Limonade

Reputation: 3

SAS proc import imports date with dots at random place. How can I solve this problem?

I've been trying to import a csv dataset to sas, but, while it imports it correctly on colleagues computer, on mine, the date of birth are imported in a weird format, for ex.: 23.102.023 instead of 23/10/2023.

I used a classic proc import (which works for colleagues):

proc import
    file="filepathandname.csv"
    out=name
    dbms=dlm
    replace;
    delimiter=";";
    getnames=yes;
   run;

What can I do?

Upvotes: 0

Views: 111

Answers (2)

Tom
Tom

Reputation: 51621

Whether or not XX.XX.XXXX is seen as a DATE or a NUMBER by PROC IMPORT will depend on your setting of the system option LOCALE.

Let's conduct an experiment. Let's make a simple CSV file and read it with PROC IMPORT using both LOCALE=EN_US and LOCALE=IT_IT.

options parmcards=csv;
filename csv temp;
parmcards4;
id,date
1,23.10.2023
;;;;

options locale=IT_IT;
proc import file=csv dbms=csv out=import_IT replace;
run;
options locale=EN_US;
proc import file=csv dbms=csv out=import_US replace;
run;

Note if you want another tool for guessing how a CSV should be read try the %CSV2DS macro as it will recognize DD.MM.YYYY strings as being date values whatever your LOCALE setting is.

enter image description here

Upvotes: 1

Rud Faden
Rud Faden

Reputation: 411

You do not have a lot of control using proc import.

You can use infile for more control.

data read ;
infile "<path>\date_format_issue.csv" dlm="," firstobs=2 obs=20 ;
input 
    id $
    date : ddmmyy10. ;
put id= date= date7. ;

run ;

Upvotes: 1

Related Questions