It’s best to either write the data step code yourself, or run PROC IMPORT, go to the log and copy / paste the read code into your program
This has a drawback. If there was a change in the structure of the csv file, for example, a changed column order, then you need to change the code in the SAS program.
Thus, it is safer to change the input by replacing the numeric fields with a comma with a dot and passing the modified input to the SAS.
The first idea was to use the perl program for this, and then use the file name in SAS with a pipe to read the modified input.
Unfortunately, there is a SAS restriction in the proc import: the IMPORT procedure does not support device types or access methods for the FILENAME statement other than DISK.
Therefore, you need to create a working file on a disk with a regulated input.
I used the CVS_PP package to read the csv file.
testdata.csv contains the csv data to read.
substitute_commasep.perl is the name of the perl program
perl code:
# use lib "/........"; # specifiy, if Text::CSV_PP is locally installed. Otherwise error message: Can't locate Text/CSV_PP.pm in ....; use Text::CSV_PP; use strict; my $csv = Text::CSV_PP->new({ binary => 1 ,sep_char => ';' }) or die "Error creating CSV object: ".Text::CSV_PP->error_diag (); open my $fhi, "<", "$ARGV[0]" or die "Error reading CSV file: $!"; while ( my $colref = $csv->getline( $fhi) ) { foreach (@$colref) { # analyze each column value s/,/\./ if /^\s*[\d,]*\s*$/; # substitute, if the field contains only numbers and , } $csv->print(\*STDOUT, $colref); print "\n"; } $csv->eof or $csv->error_diag(); close $fhi;
SAS Code:
filename readcsv pipe "perl substitute_commasep.perl testdata.csv"; filename dummy "dummy.csv"; data _null_; infile readcsv; file dummy; input; put _infile_; run; proc import datafile=dummy out=data1 dbms=dlm replace; delimiter=';'; getnames=yes; guessingrows=32767; run;
hoila source share