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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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