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
Azurite | Level 17

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1526 views
  • 0 likes
  • 3 in conversation