BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
karen_e_wallace
Obsidian | Level 7

Thank you for help in advance!

 

I want to simply read in several text files that have the same format and in the same location.

 

The files have names like "Boston_M.txt", "Boston_F.txt", etc.

 

In a macro, I'm passing the city and gender variables - and that piece is resolving per the log.

 

However, my issue is what to do about the "_" in the text file names that separates the city and gender.

 

The log states:

ERROR: Physical file does not exist, /courses/d93a3ee5ba27fe300/c_8666/BostonM.txt.

 

Could someone suggest a modification in the infile statement as I cannot change the names of the original files.

 

%macro import_files (city, gender);

data &city&gender;

infile "/courses/d93a3ee5ba27fe300/c_8666/&city&gender..txt" dlm='_' TRUNCOVER;

INPUT ID 1-3 Race $4 State 6-8 ;

/* _infile_=translate(_infile_,'_','''');*/

/* _infile_=compress(_infile_," @%/.'?""");*/

run;

%mend import_files;

1 ACCEPTED SOLUTION

Accepted Solutions
JoshB
Quartz | Level 8

Your file name has the underscore in it.. so your infile statement should as well..  i.e.

 

infile "/courses/d93a3ee5ba27fe300/c_8666/&city._&gender..txt" dlm='_' TRUNCOVER;

 

That will resolve as /courses/d93a3ee5ba27fe300/c_8666/Boston_M.txt for your example.

 

As a side note, the dlm is a file delimiter internal to the file, it has no bearing on what delimits the filename. I haven't personally seen a file that was delimited internally by underscores, but that may be what you're working with.

View solution in original post

2 REPLIES 2
JoshB
Quartz | Level 8

Your file name has the underscore in it.. so your infile statement should as well..  i.e.

 

infile "/courses/d93a3ee5ba27fe300/c_8666/&city._&gender..txt" dlm='_' TRUNCOVER;

 

That will resolve as /courses/d93a3ee5ba27fe300/c_8666/Boston_M.txt for your example.

 

As a side note, the dlm is a file delimiter internal to the file, it has no bearing on what delimits the filename. I haven't personally seen a file that was delimited internally by underscores, but that may be what you're working with.

karen_e_wallace
Obsidian | Level 7

JoshB - thanks a million! That's so simple...still a SAS newbie 🙂

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1841 views
  • 1 like
  • 2 in conversation