DATA Step, Macro, Functions and more

Reading a text file using the infile command

Reply
Occasional Contributor
Posts: 5

Reading a text file using the infile command

Hi,

I have a text file with values as mentioned below.  How to import these into SAS with the headers as 1. Date 2. Values?. The dates should be in the date column and the values to be in the other column. I dont want to edit the text file.

 

1Sep11 389.00 1Oct11 491.00 1Nov11 370.00 1Dec11 335.00

and so on.

 

Thanks in advance

Respected Advisor
Posts: 3,887

Re: Reading a text file using the infile command

@Sakthivel_Saran

Please attach your text file with the first 3 rows. That makes it much easier for us to give you a response.

Alternatively: Use the Import Task in SAS EG or SAS Studio - that might already support you enough to solve this task on your own.

Occasional Contributor
Posts: 5

Re: Reading a text file using the infile command

1Sep11 389.00 1Oct11 491.00 1Nov11 370.00 1Dec11 335.00

2Sep11 423.00 2Oct11 478.00 2Nov11 407.00 2Dec11 442.00

3Sep11 482.00 3Oct11 300.00 3Nov11 303.00 3Dec11 372.00

 

These are the first three lines of the code. I am using SAS 9.0 system for windows. Hope this helps.

Respected Advisor
Posts: 3,887

Re: Reading a text file using the infile command

@Sakthivel_Saran

You can actually ATTACH files instead of posting the data directly into the text. This is sometimes the better option as it provides us with your actual data in the actual format. 

Capture.JPG

How to import these into SAS with the headers as 1. Date 2. 

Where are these headers? Are they the first row in your text file or does your text file directly start with data? Providing the data as an attachment would anser all these questions and also allow us to show you how to use the Import Wizards.

 

You're using SAS 9.0! Why? I hope no serious organization is still using this version. Is this a"hack" version you found on Internet? If so and that's for you onw learning and not for commercial usage then dowload the official, up-to-date and free of charge SAS UE distribution here: https://www.sas.com/en_au/software/university-edition/download-software.html 

 

 

Super User
Posts: 5,077

Re: Reading a text file using the infile command

[ Edited ]

Here's an approach that should work:

 

data want;

infile rawdata;

informat date date9.;

input date value @@;

format date yymmdd10.;

run;

 

You will get a message about SAS moving to a new line when it reached past the end of the current line.  For this program, that note is expected and can be ignored.

Ask a Question
Discussion stats
  • 4 replies
  • 177 views
  • 1 like
  • 3 in conversation