Help using Base SAS procedures

Importing a space delimited .txt file

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Importing a space delimited .txt file

Hi,

I have a text file that looks like this:

State,State ANSI,County ANSI,County Name,ANSI Cl

AL,01,001,Autauga County,H1

AL,01,003,Baldwin County,H1

AL,01,005,Barbour County,H1

AL,01,007,Bibb County,H1

AL,01,009,Blount County,H1

AL,01,011,Bullock County,H1

The file is also attached.

How can I get this into SAS? I tried a few ways but I couldn't get it to have a data set with 5 columns with the corresponding headings.

Amanda

Attachment

Accepted Solutions
Solution
‎12-04-2013 05:39 PM
PROC Star
Posts: 7,356

Re: Importing a space delimited .txt file

It actually appears to be a comma delimited file.  Couldn't you just use something like:

data want;

  infile "c:\art\names.txt" dlm="," dsd firstobs=2;

  length State State_ANSI ANSI_Cl $2;

  length County_ANSI $3;

  length County_Name $50;

  input State State_ANSI County_ANSI County_Name ANSI_Cl;

run;

View solution in original post


All Replies
Solution
‎12-04-2013 05:39 PM
PROC Star
Posts: 7,356

Re: Importing a space delimited .txt file

It actually appears to be a comma delimited file.  Couldn't you just use something like:

data want;

  infile "c:\art\names.txt" dlm="," dsd firstobs=2;

  length State State_ANSI ANSI_Cl $2;

  length County_ANSI $3;

  length County_Name $50;

  input State State_ANSI County_ANSI County_Name ANSI_Cl;

run;

Contributor
Posts: 24

Re: Importing a space delimited .txt file

Sorry, yes, comma delimited. Thanks so much! The code worked perfect.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 154 views
  • 0 likes
  • 2 in conversation