BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Divya_Joseph
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Find  _ 's hex value .and 

 

delimiter='5F09'x  ;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

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.

vThanu
Calcite | Level 5

Using data step first record is not reading properly......

Kurt_Bremser
Super User

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.

 

vThanu
Calcite | Level 5
Thanks for your reply.....
While iam trying to execute the same code in SAS 9.4 not reading properly
Ksharp
Super User

Find  _ 's hex value .and 

 

delimiter='5F09'x  ;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1349 views
  • 1 like
  • 4 in conversation