BookmarkSubscribeRSS Feed
Abhi1212
Obsidian | Level 7

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

5 REPLIES 5
DartRodrigo
Lapis Lazuli | Level 10

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

Abhi1212
Obsidian | Level 7
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. -##
LinusH
Tourmaline | Level 20

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
Abhi1212
Obsidian | Level 7
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. -##
DartRodrigo
Lapis Lazuli | Level 10

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*/

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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