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;
Your file name has the underscore in it.. so your infile statement should as well.. i.e.
infile "/courses/d93a3ee5ba27fe300/c_8666/&city._&gender..t
That will resolve as /courses/d93a3ee5ba27fe300/c_8666/Boston_M.t
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.
Your file name has the underscore in it.. so your infile statement should as well.. i.e.
infile "/courses/d93a3ee5ba27fe300/c_8666/&city._&gender..t
That will resolve as /courses/d93a3ee5ba27fe300/c_8666/Boston_M.t
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.
JoshB - thanks a million! That's so simple...still a SAS newbie 🙂
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.