BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ctisseuil
Fluorite | Level 6

Hi, 

 

I'm a SAS GE user. I'd like to change my client project path, by replacing a piece of text and store the result as a macro variable. Concretely: 

 

My project directory path returned by `_CLIENTPROJECTPATH`  is  "R:\DMCD\MARK\project-file.egp". 

I want to be replace  "R:\"  by "\\srvfic4\DDOC\" and remove the ending text "project-file.egp".

I expect the final result to be stored as a macro variable, DIR_PROJ, containing the following path :  "\\srvfic4\DDOC\DMCD\MARK"

 

Here is the piece of code that I have tried, but with no success: 

 

 

%let DIR_PROJ=tranwrd(&_CLIENTPROJECTPATH,'R:\', '\\srvfic4\DDOC');
%put &DIR_PROJ;

 

Any ideas

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@ctisseuil wrote:

Hi, 

 

I'm a SAS GE user. I'd like to change my client project path, by replacing a piece of text and store the result as a macro variable. Concretely: 

 

My project directory path returned by `_CLIENTPROJECTPATH`  is  "R:\DMCD\MARK\project-file.egp". 

I want to be replace  "R:\"  by "\\srvfic4\DDOC\" and remove the ending text "project-file.egp".

I expect the final result to be stored as a macro variable, DIR_PROJ, containing the following path :  "\\srvfic4\DDOC\DMCD\MARK"

 

Here is the piece of code that I have tried, but with no success: 

 

 

%let DIR_PROJ=tranwrd(&_CLIENTPROJECTPATH,'R:\', '\\srvfic4\DDOC');
%put &DIR_PROJ;

 

Any ideas

 


To use data step functions such as TRANWRD in macro code you have to wrap the call in %sysfunc () for each function to tell the processor that you want it applied.

With the macro processor you don't use the quotes as they will be part of the value.

%let _CLIENTPROJECTPATH=R:\DMCD\MARK\project-file.egp;

%let DIR_PROJ=%sysfunc(tranwrd(&_CLIENTPROJECTPATH.,R:\,\\srvfic4\DDOC));
%put &DIR_PROJ;

Caution with just any characters in the macro language, since & and % have meaning to the macro processor you may have to use functions to mask the them if you need to use them in a string function as a literal value. You have been warned.

 

It is not entirely clear when you just wanted to extract the path for the result or modify the path and still point to the same named file. I interpreted the request as the later.

View solution in original post

2 REPLIES 2
ballardw
Super User

@ctisseuil wrote:

Hi, 

 

I'm a SAS GE user. I'd like to change my client project path, by replacing a piece of text and store the result as a macro variable. Concretely: 

 

My project directory path returned by `_CLIENTPROJECTPATH`  is  "R:\DMCD\MARK\project-file.egp". 

I want to be replace  "R:\"  by "\\srvfic4\DDOC\" and remove the ending text "project-file.egp".

I expect the final result to be stored as a macro variable, DIR_PROJ, containing the following path :  "\\srvfic4\DDOC\DMCD\MARK"

 

Here is the piece of code that I have tried, but with no success: 

 

 

%let DIR_PROJ=tranwrd(&_CLIENTPROJECTPATH,'R:\', '\\srvfic4\DDOC');
%put &DIR_PROJ;

 

Any ideas

 


To use data step functions such as TRANWRD in macro code you have to wrap the call in %sysfunc () for each function to tell the processor that you want it applied.

With the macro processor you don't use the quotes as they will be part of the value.

%let _CLIENTPROJECTPATH=R:\DMCD\MARK\project-file.egp;

%let DIR_PROJ=%sysfunc(tranwrd(&_CLIENTPROJECTPATH.,R:\,\\srvfic4\DDOC));
%put &DIR_PROJ;

Caution with just any characters in the macro language, since & and % have meaning to the macro processor you may have to use functions to mask the them if you need to use them in a string function as a literal value. You have been warned.

 

It is not entirely clear when you just wanted to extract the path for the result or modify the path and still point to the same named file. I interpreted the request as the later.

ctisseuil
Fluorite | Level 6
Thank you very much !

It works wonderfully 🙂

Have a good day

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2 replies
  • 1075 views
  • 0 likes
  • 2 in conversation