DATA Step, Macro, Functions and more

Reading a data from external file in SAS

Reply
Contributor
Posts: 31

Reading a data from external file in SAS

Hi,

How to read a data from an external file and store it in a variable.

 

For example,

Say i have a external file with 62K thousand records. There is no space delimiters nothing. However, i need to read 1 to 30k records and store it A variable and 30K to 60l records i need to store it in B variable. Please guide me how i can achieve.

 

Thanks,

Abhi

Regular Contributor
Posts: 212

Re: Reading a data from external file in SAS

[ Edited ]

Hi mate,

 

Try to use the infile and input:

 

One for the first 30000 values:
  Infile "Your-file.txt" dlm = " " firstobs=1 obs=30000;
  input #1 entire_row1 $1-220;

One for the last values:
  Infile "Your-file.txt" dlm = " " firstobs=30000 obs=62000;
  input #1 entire_row2 $1-220;

Hope this helps

Contributor
Posts: 31

Re: Reading a data from external file in SAS

Where u r defining the variable like. . Which set of data will be set in A
variable and which in B?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 5,256

Re: Reading a data from external file in SAS

It's a bit unclear what you want to do.

Do you have a text file that is just...text...no natural variables...?

And then, you want to store 30K (no of?) records (how long is a record) into a variable. A data set variable?

Could it be that you are mixing up the terminology. 30K of text (chars), into one variable...?

 

Then, I'm a bit curious, what's the application?

Data never sleeps
Contributor
Posts: 31

Re: Reading a data from external file in SAS

Hi,
The file is seem to be like extracted from copybook.. As I already
explained. .With that data I need to create a table in SAS. I have
attached the template and raw data. The data starts from ALH ends with the
time. At the middle we have delimiters space and ^T we have to avoid those.
And if suppose the file exceeds the maximum variable size which is 32K at
that case how can I read the data. This is my question.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Regular Contributor
Posts: 212

Re: Reading a data from external file in SAS

In my guess, Linus, he want to split his import in two variables.

From the line 1 to 32k will be set in variable A and the last lines will be set in variable B.

 

Just like

 

infile "file" firstobs=1 obs=32000;
input Entire_Row1 $1-220; /*This var starts in line one until 32k*/

input Entire_Row2 $1-220; /*This var starts in line 32001 until 62k*/

Ask a Question
Discussion stats
  • 5 replies
  • 269 views
  • 0 likes
  • 3 in conversation