BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
acros
Calcite | Level 5

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 Name75
Address 150
Address 250
Address 350
City50
State2
Zip Code15
Phone50
Fax50

How can I import this into SAS?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

3 REPLIES 3
JuanS_OCS
Amethyst | Level 16

Hi,

you can proc import on a very easy way.

I suggest you this publication: simple, and clear:

SAS FAQ: How do I read in a file that uses commas, tabs or spaces as delimiters to separate variable...

But you can also refer to the complete and official documentation:

http://support.sas.com/techsup/technote/ts673.pdf

Tom
Super User Tom
Super User

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;

acros
Calcite | Level 5

Amazing! So simple. Thanks, Tom!

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!

What is Bayesian Analysis?

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.

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
  • 3 replies
  • 780 views
  • 0 likes
  • 3 in conversation