Hi all,
I am trying to import text file which contains delimiters such as tab and _ . Underscore is working. But Tab is not working.
proc import datafile='C:\Users\bijo\Documents\SAS Practice\ImportText2.txt'
out=p1
dbms=dlm replace;
delimiter='_ '09'x ' ;
Getnames=no;
proc print;
run;
Please help
Translate the tabs to underlines first, and use the underlines as standard delimiter:
data test;
infile datalines dlm='_' dsd;
input @;
_infile_ = translate(_infile_,'_','09'x);
input city :$20. state : $20. val1 val2;
datalines;
Melbourne_Victoria 240 600
Sydney_nsw_120_430
Adelaide_SA_400_500
;
run;
The first input is just there to fill the buffer (_infile_), and holds the line (@). The second input reads the data.
proc import is not able to handle such a situation.
Using data step first record is not reading properly......
Use firstobs=2 in the infile statement to skip the header.
Otherwise, my code (copy/pasted from here directly to the EG Enhanced Editor and submitted):
data test;
infile datalines dlm='_' dsd;
input @;
_infile_ = translate(_infile_,'_','09'x);
input city :$20. state : $20. val1 val2;
datalines;
Melbourne_Victoria 240 600
Sydney_nsw_120_430
Adelaide_SA_400_500
;
run;
proc print data=test noobs;
run;
produces this result:
city state val1 val2 Melbourne Victoria 240 600 Sydney nsw 120 430 Adelaide SA 400 500
If you have any trouble, post log ({i} button!) and results.
Find _ 's hex value .and
delimiter='5F09'x ;
Thank you
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!
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.
Ready to level-up your skills? Choose your own adventure.