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
SAS Super FREQ
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 821 views
  • 0 likes
  • 5 in conversation