DATA Step, Macro, Functions and more

Urgent help for importing txt format data into SAS

Reply
Contributor QLi
Contributor
Posts: 57

Urgent help for importing txt format data into SAS

I have this kind data in txt format. I need urgent help to import into SAS data set.
------------------------------------------------------------------------------------
| 193100 | 20100331 | 97 | 3 |
-------------------------------------------------------------------------------------
| 200998 | 20100331 | 97 | 4 |
-------------------------------------------------------------------------------------
| 201707 | 20100331 | 97 | 2 |
-------------------------------------------------------------------------------------
| 215848 | 20100331 | 97 | 1 |
-------------------------------------------------------------------------------------
| 233171 | 20100331 | 97 | 3 |
-------------------------------------------------------------------------------------
| 250530 | 20100331 | 97 | 16 |
-------------------------------------------------------------------------------------


Thanks
SAS Super FREQ
Posts: 8,743

Re: Urgent help for importing txt format data into SAS

Hi:
Does your data have the rows of dashes (-----------------------------) and the pipe characters between each column ( | )?????

Reading a TXT file into SAS is fairly simple. You might use PROC IMPORT or you might use the IMPORT Wizard (in Enterprise Guide) or you might use a DATA step program with INFILE and INPUT statements.

Here's a good place to start reading (and there are a lot of examples here in the documentation -- one of them should fit your data scenario):
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001302670.htm

cynthia
N/A
Posts: 0

Re: Urgent help for importing txt format data into SAS

It can be done as -
data data1;
infile 'c:\mtdata.txt';
input var1-var4;
run;
Respected Advisor
Posts: 3,892

Re: Urgent help for importing txt format data into SAS

data want(drop=_dummy_);
infile datalines dlm='|' dsd truncover;
input @1 _dummy_:$1. @;
if _dummy_ ne '-' then
do;
input var1 var2 var3 var4;
output;
end;
datalines;
------------------------------------------------------------------------------------
| 193100 | 20100331 | 97 | 3 |
-------------------------------------------------------------------------------------
| 200998 | 20100331 | 97 | 4 |
-------------------------------------------------------------------------------------
| 201707 | 20100331 | 97 | 2 |
-------------------------------------------------------------------------------------
| 215848 | 20100331 | 97 | 1 |
-------------------------------------------------------------------------------------
| 233171 | 20100331 | 97 | 3 |
-------------------------------------------------------------------------------------
| 250530 | 20100331 | 97 | 16 |
-------------------------------------------------------------------------------------
;
run;

proc print data=want;
run;




HTH
Patrick
PROC Star
Posts: 1,561

Re: Urgent help for importing txt format data into SAS

or even

data want;
infile datalines dlm='|' dsd truncover;
input @;
if _infile_ ne: '-' ;
input @3 var1 var2 var3 var4;
datalines;
Ask a Question
Discussion stats
  • 4 replies
  • 192 views
  • 0 likes
  • 5 in conversation