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
@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 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.
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!
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.