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: Call for Content

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!

Submit your idea!

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