DATA Step, Macro, Functions and more

How to get long strings as input

Accepted Solution Solved
Reply
PROC Star
Posts: 1,167
Accepted Solution

How to get long strings as input

I'm having so much fun! I should have quit working years ago!!

Anyway, I've encountered situations in the past where I just want to grab the rows of an input file "in bulk", and do things to them using DATA step code. For years, I've been using the following code:

data work.test_data;
infile "C:\some_file.txt" lrecl=32767;
length inrec $ 32767;
input;
inrec = _infile_;

/* and then use inrec as my source of text for further processing, using string functions or PRX functions or whatever */

run;

I like it because I consider it the bare minimum, but would any changes improve it? Are there any conditions under which it won't work?

Thanks,

  Tom


Accepted Solutions
Solution
‎10-02-2012 07:43 PM
PROC Star
Posts: 7,487

Re: How to get long strings as input

Tom,

My personal preference, in such cases, is to use input @, modify _infile_ as needed, and then just use a normal input statement to re-read the modified data row.

View solution in original post


All Replies
Solution
‎10-02-2012 07:43 PM
PROC Star
Posts: 7,487

Re: How to get long strings as input

Tom,

My personal preference, in such cases, is to use input @, modify _infile_ as needed, and then just use a normal input statement to re-read the modified data row.

Super User
Posts: 10,041

Re: How to get long strings as input

NO. Your code looks good. Here is an instead way.

data work.test_data;

infile "C:\some_file.txt"  length=len lrecl=32767;

input inrec $varying32676. len;

run;

Super Contributor
Posts: 474

Re: How to get long strings as input

Working with the RAW input record is perfectly OK and reasonable from my understanding,

but why not just use the automatic _infile_ variable and work from there?

I really don't see no need to copy it's content to a second variable, a 32K PDV is quite big in memory.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt

PROC Star
Posts: 1,167

Re: How to get long strings as input

I guess after a couple of days with no responses we can consider this closed.

Thank you all - I learned something useful from each of your answers, and will absolutely try them all out.

Please don't be offended - I was going to mark you all "Correct Answer", but I've never awarded these before and just discovered that there are limits on numbers - statistically, I consider this a poor practice   ;-)

So Art gets the green star for being first (and maybe for being a fellow Canuck?)

Happy Thanksgiving and Columbus Day to all of you!

  Tom

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 330 views
  • 6 likes
  • 4 in conversation