BookmarkSubscribeRSS Feed
GeorgeSAS
Lapis Lazuli | Level 10

Hello all;

 

I want read a very large .txt file in to SAS and make some midification on its value. after doing that I want to output them back to raw .txt file. but I don't want change any characters' original location in txt file. what can I do?

 

Thanks!

3 REPLIES 3
JuanS_OCS
Amethyst | Level 16

Hi,

 

I am sure others can provide better suggestions. For now:

- do you use Enterprise Guide? If you do, you might fins useful this tip from Chris Hemedinger https://communities.sas.com/t5/SAS-Enterprise-Guide/Importing-Extremely-Large-Text-File/td-p/152222

- anyway, you could always load the data of the txt file into a SAS dataset, then you can make the transformation on the dataset, then load the dataset into a different txt file.

 

Probably there is another method much more optimal, with less steps, but, for now can now work with this procedure

 

If you need support with the statements, you can always give a look into the SAS help manual, or ask around over here 🙂

Tom
Super User Tom
Super User

There is an example of how to do that in the help pages for the INFILE statement.

http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#n1rill4udj0tfun...

 

Example 6: Updating an External File

This example shows how to use the INFILE statement with the SHAREBUFFERS option and the INPUT, FILE, and PUT statements to update an external file in place:
data _null_;
     /* The INFILE and FILE statements     */
     /* must specify the same file.       */
   infile file-specification-1 sharebuffers;
   file file-specification-1;
   input state $ 1-2 phone $ 5-16; 
     /* Replace area code for NC exchanges */
   if state= 'NC' and substr(phone,5,3)='333' then
     phone='910-'||substr(phone,5,8);
   put phone 5-16;
run;
ballardw
Super User

I strongly recommend that while developing this process that you write to a different file. You can use options like OBS= and FIRSTOBS= to process just a few specified lines of a file.

 

 

And unless you do not have space to store the original and the modified files I would recommend creating a new file in general. Writing over your only copy of a set is rife with possibilities of corrupt data.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 2273 views
  • 7 likes
  • 4 in conversation