BookmarkSubscribeRSS Feed
QLi
Fluorite | Level 6 QLi
Fluorite | Level 6
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
4 REPLIES 4
Cynthia_sas
Diamond | Level 26
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
deleted_user
Not applicable
It can be done as -
data data1;
infile 'c:\mtdata.txt';
input var1-var4;
run;
Patrick
Opal | Level 21
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
ChrisNZ
Tourmaline | Level 20
or even

data want;
infile datalines dlm='|' dsd truncover;
input @;
if _infile_ ne: '-' ;
input @3 var1 var2 var3 var4;
datalines;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1681 views
  • 0 likes
  • 5 in conversation