The below code has \ back slash in it's infile statement and while I run on UNIX it's not reading it. I have 20 similar programs like this. Is there any macro that I can convert the \ to / forward while running the program?
data a;
infile '.\example2.txt' truncover;
input fname :$20. lname :$30. address1 :$50. address2 :$50. city :$40.
state :$2. zip phone :$12.;
run;
@RAVI2000 wrote:
How can I change programmatically? I don't wish to do a manual correction.
For 20 programs? Just open them one by one and use the CHANGE or REPLACE command of your editor of choice.
If did want to write a program it should not be that hard. First let's make an example program file.
options parmcards=example;
filename example temp;
parmcards4;
data a;
infile '.\example2.txt' truncover;
input fname :$20. lname :$30. address1 :$50. address2 :$50. city :$40.
state :$2. zip phone :$12.;
run;
;;;;
Now let's run a step to convert the \ to /. You might want to limit the change to just the INFILE statements.
filename fixed temp;
data _null_;
infile example;
file fixed ;
input;
if left(upcase(_infile_))=:'INFILE' then _infile_=translate(_infile_,'/','\');
put _infile_;
run;
Results:
data a; infile './example2.txt' truncover; input fname :$20. lname :$30. address1 :$50. address2 :$50. city :$40. state :$2. zip phone :$12.; run;
You can always use the forward slash for file paths in SAS, even when running on Windows (where backslash is the norm). No need to maintain two versions or detect the OS and switch between / and \.
So best practice: change your programs to use the forward slash and don't worry about it!
@RAVI2000 wrote:
How can I change programmatically? I don't wish to do a manual correction.
For 20 programs? Just open them one by one and use the CHANGE or REPLACE command of your editor of choice.
If did want to write a program it should not be that hard. First let's make an example program file.
options parmcards=example;
filename example temp;
parmcards4;
data a;
infile '.\example2.txt' truncover;
input fname :$20. lname :$30. address1 :$50. address2 :$50. city :$40.
state :$2. zip phone :$12.;
run;
;;;;
Now let's run a step to convert the \ to /. You might want to limit the change to just the INFILE statements.
filename fixed temp;
data _null_;
infile example;
file fixed ;
input;
if left(upcase(_infile_))=:'INFILE' then _infile_=translate(_infile_,'/','\');
put _infile_;
run;
Results:
data a; infile './example2.txt' truncover; input fname :$20. lname :$30. address1 :$50. address2 :$50. city :$40. state :$2. zip phone :$12.; run;
And while you are at it, I strongly recommend to replace the relative path with an absolute one. The current working directory depends on the way SAS is started, so you can't trust it to be what you expect. On UNIX, one usually puts files into the home directory, so you can always use $HOME.
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.