BookmarkSubscribeRSS Feed
Banu
Obsidian | Level 7

Hi, Can you help me to read below format .txt file into SAS.

 

Data Record looks like below.

 

1234567890|202020| |12345.000000000000|12345.000000000000| |2020-01-01T05:29:50.000-05:00|2022-01-31

 

Please help me to read into SAS.

4 REPLIES 4
PGStats
Opal | Level 21

Use DLM="|" option in the infile statement. Then look in the SAS informat library to find the unput format appropriate for each field in your input statement.

PG
Reeza
Super User
data imported;
infile "path to file" dlm="|" truncover;

*specify the informat of the variables - this tells SAS how they look so they are read in properly;

informat var7 anydtdtm. var8 yymmdd10.;
format var7 datetime20. var8 date9.;

input var1 var2 var3 var4 var5 var6 var7 var8;
;;;;
run;

Fill in the variable names with something that means something to you. If the order of the variables is important you'll want to specify the informats for all your variables. 

 


@Banu wrote:

Hi, Can you help me to read below format .txt file into SAS.

 

Data Record looks like below.

 

1234567890|202020| |12345.000000000000|12345.000000000000| |2020-01-01T05:29:50.000-05:00|2022-01-31

 

Please help me to read into SAS.


 

Ksharp
Super User
data have;
input;
length temp $ 2000;
retain temp;
temp=cats(temp,_infile_);
if countw(temp,'|','m')=8 then do;
t1=scan(temp,1,'|','m');
t2=scan(temp,2,'|','m');
t3=scan(temp,3,'|','m');
t4=scan(temp,4,'|','m');
t5=scan(temp,5,'|','m');
t6=scan(temp,6,'|','m');
t7=scan(temp,7,'|','m');
t8=scan(temp,8,'|','m');
output;call missing(temp);end;
cards;
1234567890|202020| |12345.000000000000|12345.000000000000| 
|2020-01-01T05:29:50.000-05:00|2022-01-31
1234567890|202020| |12345.000000000000|12345.000000000000| 
|2020-01-01T05:29:50.000-05:00|2022-01-31
;



proc print;run;
Kurt_Bremser
Super User

Just use the correct delimiter in the infile statement, and proper informats for the date and datetime values. Since the source of the data was prudent in using ISO 8601 formats, use the proper informats:

data want;
infile datalines dlm='|' dsd truncover;
input
  var1
  var2
  var3 $
  var4
  var5
  var6 $
  var7 :e8601dz29.
  var8 :e8601da10.
;
format
  var7 e8601dz29.3
  var8 e8601da10.
;
datalines;
1234567890|202020| |12345.000000000000|12345.000000000000| |2020-01-01T05:29:50.123-05:00|2022-01-31
;

proc print data=want noobs;
run;

Result:

   var1        var2     var3     var4     var5    var6    var7                             var8

1234567890    202020            12345    12345            2020-01-01T10:29:50.123+00:00    2022-01-31

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
  • 4 replies
  • 2654 views
  • 4 likes
  • 5 in conversation