BookmarkSubscribeRSS Feed
fordcr2
Obsidian | Level 7

Hello, 

 

I am trying to import multiple text files into one SAS file from a server. I figured I needed to use a macro to do so, but the filenames are formatted like this: test-20181002-170338-230. So what I need to do is import hundreds of these files names in this format but with different numbers (ex. test-xxxxxxxx-xxxxxx-xxx) all at once. 

 

Does anyone have any ideas on how I could do this?

 

Thanks!

 

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

There are several options.  Do a search on here and you will find lots of posts on the subject, "importing multiple csv files" is a good term to search for.

One simple option: Get a list from os using pie, then call execute a macro call or code to import the file from a datastep.

fordcr2
Obsidian | Level 7

I've found some options for importing the files but my issue is with the filenames as SAS does not like files with -'s in them. Is there an additional macro I need to use to solve this?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

SAS has no problems importing files with "-" in at all.  Just ran this fine:

data want;
  length tmp $200;
  infile "&_sasws_./temp-2010101.txt";
  input tmp $;
run;

No issues at all.

"I am also importing xml files, not csv."

Irrelevant.  You are importing a text file, setup is exactly the same, just different call/engine used to read the data.  Its still both text files.

ballardw
Super User

@fordcr2 wrote:

I've found some options for importing the files but my issue is with the filenames as SAS does not like files with -'s in them. Is there an additional macro I need to use to solve this?


Once you have string with the original name to read with you can modify that string to something SAS will accept for SAS dataset names. The example code below shows changing all of the dash to underscores which are valid in SAS dataset names.

 

data example;
   x='test-20181002-170338-230';
   y=translate(x,'_','-');
run;
fordcr2
Obsidian | Level 7

I am also importing xml files, not csv.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1138 views
  • 0 likes
  • 3 in conversation