DATA Step, Macro, Functions and more

Do we have an equivalent infile option

Reply
N/A
Posts: 0

Do we have an equivalent infile option

Hi,

I am trying to read a text file using "infile" statement, where data can come in either of delimiters - comma or tilda.

We have only SAS 8.2 Version. I saw that this option in infile statement - DLMSTR has facility to read either of ways that data will come and is applicable in SAS 9 version.

Do we have an equivalent option in SAS 8.2 Version. If not, how to read data if the file comes in either of those above delimiters?

thanks in advance,
Sasbase9
Regular Contributor
Posts: 151

Re: Do we have an equivalent infile option

Posted in reply to deleted_user
If I understand your question correctly than you can do following:

[pre]
data cc;
infile cards dlm=',~';
input a $ b $ c ;
cards;
A,1,13
B~2,15
c,D~20
;
[/pre]

Oleg. Message was edited by: Oleg_L
Frequent Contributor
Posts: 91

Re: Do we have an equivalent infile option

I ran Oleg_L's code on a mainframe with SAS8.2 and it worked.
Valued Guide
Posts: 2,177

Re: Do we have an equivalent infile option

the DLM='constant' option of the infile statement lists alternative delimiters all/any of which are used to parse the infile buffer
When you need to use different delimiters at different stages of input, use DLM=variable. The variable can change during the running of the data step in ways that the 'constant' cannot.

peterC emphasise that characters in the DLM are alternatives

Message was edited by: Peter.C
Super User
Posts: 10,035

Re: Do we have an equivalent infile option

Posted in reply to deleted_user
Hi.
Maybe you can use scan() function to achieve it.
Not test.

[pre]
data cc;
infile cards;
input ;
a=scan(_infile_,1,',~');
b=scan(_infile_,2,',~');
c=scan(_infile_,3,',~');
cards;
A,1,13
B~2,15
c,D~20
;
run;
proc print noobs; run;
[/pre]


Ksharp
Regular Contributor
Posts: 241

Re: Do we have an equivalent infile option

Posted in reply to deleted_user
...
> I saw that this option
> in infile statement - DLMSTR has facility to read
> either of ways that data will come and is applicable
> in SAS 9 version.
...
No. DLMSTR= option lets you specify a multi-character delimiter. DLM= option lets you specify single-character delimiter(s). A rather big difference.
[pre]
data one;
infile cards dlmstr="+|+" missover;
input (v1-v3) (:$8.);
cards;
1+++|+2||++|+3
;
run;

proc print data=one;
run;
/* on lst
Obs v1 v2 v3
1 1++ 2||+ 3
*/


data two;
infile cards dlm="+|+" missover;
input (v1-v3) (:$8.);
cards;
1+++|+2||++|+3
;
run;

proc print data=two;
run;
/* on lst
Obs v1 v2 v3
1 1 2 3
*/
[/pre]
Ask a Question
Discussion stats
  • 5 replies
  • 264 views
  • 0 likes
  • 6 in conversation