Hi all,
Would you know how I could read a CSV in which the delimiter as been set to a double pipe ('||') ? An empty value in this file would thus appear like 4 consecutive pipe ('||||'). We are still using the version 8 of SAS :smileylaugh:
I already know how to create such a file but not how to read it :smileyconfused:
Many thanks in advance for your help !
Kind regards,
Florent
hi ... I think that _INFILE_ has been around since V8, so maybe ...
data x;
infile datalines dsd;
input @;
_infile_ = tranwrd(_infile_,'||',',');
input a b c;
datalines;
1||2||||
4||5||6
||8||||
;
a b c
1 2 .
4 5 6
. 8 .
ps ... some reading material ...
More _Infile_ Magic, Peter Crawford
http://www2.sas.com/proceedings/sugi28/086-28.pdf
Now _INFILE_ is an Automatic Variable − So What?, Howard Schreier,
hi ... I think that _INFILE_ has been around since V8, so maybe ...
data x;
infile datalines dsd;
input @;
_infile_ = tranwrd(_infile_,'||',',');
input a b c;
datalines;
1||2||||
4||5||6
||8||||
;
a b c
1 2 .
4 5 6
. 8 .
ps ... some reading material ...
More _Infile_ Magic, Peter Crawford
http://www2.sas.com/proceedings/sugi28/086-28.pdf
Now _INFILE_ is an Automatic Variable − So What?, Howard Schreier,
Thanks, it makes the job !
Nice solution, but I'm not sure you should use dsd here. The way I understood the data structure, a double delimiter indicates there is a blank variable. If that's the case, dsd should become dlm=','
hi ... DSD implies a few things: a comma-delimiter; two consecutive commas indicate a missing value; considers delimiters within quotes as character data and strips quotes from quoted values
DLM=',' only does the comma-delimter portion
my example doesn't work with just DLM
You're right, I'm temporarily brain-fried. Sorry about that.
Hi, My concern would be that a file separated this way might contain commas in numeric or character fields. It might be safer to keep the pipe character as in:
data x;
infile datalines delimiter='|' dsd;
input @;
_infile_ = tranwrd(_infile_,'||','|');
input (a b c) (:$);
datalines;
1||2,5||||
4||5||6
||8||||
;
PG
I agree that changing the delimiter to comma might cause problem. I would choose a character that is even more obscure. Something untypeable perhaps.
The NUL character, of course! :smileylaugh:
PG
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.