DATA Step, Macro, Functions and more

Help! How do I ttreat the underscore in these text files I'm reading?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Help! How do I ttreat the underscore in these text files I'm reading?

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;


Accepted Solutions
Solution
‎12-05-2015 02:43 PM
Contributor
Posts: 56

Re: Help! How do I ttreat the underscore in these text files I'm reading?

[ Edited ]
Posted in reply to karen_e_wallace

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


All Replies
Solution
‎12-05-2015 02:43 PM
Contributor
Posts: 56

Re: Help! How do I ttreat the underscore in these text files I'm reading?

[ Edited ]
Posted in reply to karen_e_wallace

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.

Occasional Contributor
Posts: 14

Re: Help! How do I ttreat the underscore in these text files I'm reading?

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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