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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2556 views
  • 1 like
  • 2 in conversation