Hi,
I have a .txt file that looks like this:
Advanced Breast Center|Carr. 14 KM 72.2|Plaza Milliangie||Cayey|PR|00736|787738-8077|787735-0718
Advanced Diagnostic Imaging Center, LLC|1728 Village Park Dr.|||Orangeburg|SC|29118|803536-1106|803535-6033
Advanced Diagnostic Radiology, LLC|952 Seton Dr.|||Cumberland|MD|21502|301777-3522|301777-1902
Advanced Imaging|35 Batavia City Centre Main St|||Batavia|NY|14020|585345-9729|585345-9823
So it looks like it is "|" delimited, and I also have this information- Fields Name and Field Length:
Facility Name | 75 |
Address 1 | 50 |
Address 2 | 50 |
Address 3 | 50 |
City | 50 |
State | 2 |
Zip Code | 15 |
Phone | 50 |
Fax | 50 |
How can I import this into SAS?
Copy your simple variable definitions and paste them into your program editor and turn them into a LENGTH statement. The basically will involve adding the keyword LENGTH before, editing the names to be valid SAS variable names (getting rid of the embedded spaces), add a $ before the length for character strings (for numeric variables don't add the $ but do convert the "length" to 8 since SAS stores all numbers as 8 byte floating point numbers) and add a semicolon on the end. Then just use it in a simple DATA step.
data want ;
length
FacilityName $75
Address1 $50
Address2 $50
Address3 $50
City $50
State $2
ZipCode $15
Phone $50
Fax $50
;
infile 'myfile.txt' dsd dlm='|' truncover lrecl=400 ;
input FacilityName -- Fax ;
run;
Hi,
you can proc import on a very easy way.
I suggest you this publication: simple, and clear:
But you can also refer to the complete and official documentation:
Copy your simple variable definitions and paste them into your program editor and turn them into a LENGTH statement. The basically will involve adding the keyword LENGTH before, editing the names to be valid SAS variable names (getting rid of the embedded spaces), add a $ before the length for character strings (for numeric variables don't add the $ but do convert the "length" to 8 since SAS stores all numbers as 8 byte floating point numbers) and add a semicolon on the end. Then just use it in a simple DATA step.
data want ;
length
FacilityName $75
Address1 $50
Address2 $50
Address3 $50
City $50
State $2
ZipCode $15
Phone $50
Fax $50
;
infile 'myfile.txt' dsd dlm='|' truncover lrecl=400 ;
input FacilityName -- Fax ;
run;
Amazing! So simple. Thanks, Tom!
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.