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 Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1232 views
  • 4 likes
  • 4 in conversation