Hi Friends,
I'm using SAS Studio 3.6 and I want to get the a sub directory paths from macro string.
Ex. - I have string &path as below -
%let path=&_SASPROGRAMFILE ;
%put &path;
C:\myfile\souce\ABC123\XYZ111\code\prg\myprg.sas
from above path I want to create macros which should give me subdirectory paths like -
root=C:\myfile\souce\
project=ABC123
Study=XYZ111
The folder structures are standard from project to project and study to study. so My aim is to assign libraries autoamtically somthing like this.
libname raw "&root.\&project.\&study\data\raw";
Thanks,
- Nikhil
Do it in a data step and use call symput:
%let path=C:\myfile\souce\ABC123\XYZ111\code\prg\myprg.sas;
data _null_;
path = "&path";
parts = countw(path,'\');
length root $200 project study $50;
do i = 1 to parts - 5;
root = catx('\',root,scan(path,i,'\'));
end;
project = scan(path,parts - 4,'\');
study = scan(path,parts - 3,'\');
call symput('root',trim(root));
call symput('project',trim(project));
call symput('study',trim(study));
run;
Do it in a data step and use call symput:
%let path=C:\myfile\souce\ABC123\XYZ111\code\prg\myprg.sas;
data _null_;
path = "&path";
parts = countw(path,'\');
length root $200 project study $50;
do i = 1 to parts - 5;
root = catx('\',root,scan(path,i,'\'));
end;
project = scan(path,parts - 4,'\');
study = scan(path,parts - 3,'\');
call symput('root',trim(root));
call symput('project',trim(project));
call symput('study',trim(study));
run;
Thank you Kurt!
It served my purpose perfectly.
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 25. Read more here about why you should contribute and what is in it for you!
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.