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!

SAS Innovate 2025: Call for Content! Submit your proposals before Sept 16. Accepted presenters get amazing perks to attend the conference!
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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1345 views
  • 4 likes
  • 4 in conversation