BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RAVI2000
Lapis Lazuli | Level 10

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@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;

 

View solution in original post

5 REPLIES 5
ChrisHemedinger
Community Manager

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!

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
RAVI2000
Lapis Lazuli | Level 10
How can I change programmatically? I don't wish to do a manual correction.
Tom
Super User Tom
Super User

@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;

 

RAVI2000
Lapis Lazuli | Level 10
Just one last question. Since all the 20 .sas file are NOT in same folder. Do I have to give 20 filename statements?
Kurt_Bremser
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1476 views
  • 4 likes
  • 4 in conversation