BookmarkSubscribeRSS Feed
raveena
Obsidian | Level 7

Hi ,

I have a folder that has multiple text files as below.

\\hfn5\SASPROD\H10521R1.TXT

\\hfn5\SASPROD\H10522R1.TXT

\\hfn5\SASPROD\H10523R1.TXT

\\hfn5\SASPROD\H10524R1.TXT

\\hfn5\SASPROD\H10525R1.TXT

\\hfn5\SASPROD\H10526R1.TXT

I need to read all text files data from the above folder by using macro code instead of infile statement because the files will get updated frequently and create a sas dataset for further analysis.

Please help me how to create a macro to read all txt files data in the sas dataset ?

Thanks for your help.

5 REPLIES 5
Linlin
Lapis Lazuli | Level 10
art297
Opal | Level 21

From your explanation I don't see how a macro would be better than a route similar to what Linlin suggested.  I do have a couple of questions, though.  What will determine if a file should be imported?  Do all of the files end up getting appended to one SAS file?  Do the files that were already uploaded have to be replaced and/or updated?

raveena
Obsidian | Level 7

Yes Arthur, once the file was imported it has to be append into one SAS file.Once in a week the additional files will get uploaded to the production folder, inorder to avoid the programming changes everytime we tried to create a macro that reads a additional and existing file from the folder.

Ksharp
Super User

If I were you, I will use infile + filevar=  . it is very easy and flexility .

ArtC
Rhodochrosite | Level 12

Am I missing something or is it as simple as adding a wildcard into the FILENAME statement:

filename intxt "c:\temp\xx*.txt";

data want;

   infile intxt;

   input var $;

   run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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