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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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;
nikhilwagh
Obsidian | Level 7

Thank you Kurt!

It served my purpose perfectly.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2120 views
  • 1 like
  • 2 in conversation