DATA Step, Macro, Functions and more

How to change directory name automaticly

Accepted Solution Solved
Reply
Contributor Moh
Contributor
Posts: 20
Accepted Solution

How to change directory name automaticly

hi folks - 

 

I have got the following directory and need to be changed automatically once I change the years.

 

%let dir2=M:\Lib\T9099H0103Y\T9099H0103Y_CO;

libname coeficents "&dir2"

 

%let DT=90;

%let UT=99;

%let DH=01;

%let UH=03;

 

To be clearer, I want by changing DT, UT,DH and UH  the directory path changes. thanks 

 

 

 


Accepted Solutions
Solution
‎01-27-2016 11:26 AM
Super User
Posts: 5,498

Re: How to change directory name automaticly

[ Edited ]

You will need to move the %LET statements so that they come before the directory path:

 

%let DT=90;

%let UT=99;

%let DH=01;

%let UH=03;

 

%let dir2=M:\Lib\T&DT.&UT.H&DH.&UH.Y_CO;

libname coeficents "&dir2";

 

It's not clear from your post whether these are the exact changes to make to the directory path, but this gives you the technique to apply.

 

Good luck.

View solution in original post


All Replies
Super User
Posts: 19,770

Re: How to change directory name automaticly

I'm not following, please explain your problem further.

Contributor Moh
Contributor
Posts: 20

Re: How to change directory name automaticly

 

 For example I have got this dir path;

%let dir2=M:\Lib\T9099H0103Y;

libname coeficents "&dir2"

 

Now i want to change the path according to the following items

%let DT=91;

%let UT=97;

%let DH=02;

%let UH=05;

 

to have this new directory at the end;

%let dir2=M:\Lib\T9197H0205Y;

 

 

Super User
Posts: 19,770

Re: How to change directory name automaticly

I don't understand still...I guess you could use a macro.But how did the mapping occur? How do you know to switch from

 

 

 

Is it something like:

 

%let dir2= M:\Lib\&DT.&UT.H&DH.&UH.Y;

libname coeficents "&dir2"

Contributor Moh
Contributor
Posts: 20

Re: How to change directory name automaticly

Your question is not clear. I have the results of about 100 types of models which are developed using different training samples and will be tested on different holdout samples. So I need to arrange them in different folders and name the folders based on training sample (e.g. T9199 ) which mean 1991 to 1999 and holdout sample (e.g. H0105) which means 2001 to 2005. 

However, your answer helped me a lot. thanks 

Super User
Posts: 19,770

Re: How to change directory name automaticly

A libname can only be 8 characters, your current name is too long.

 

You don't need two macro variables as well, can use one directly.

 

%let DT=90;

%let UT=99;

%let DH=01;

%let UH=03;

 

 

libname mylib  "M:\Lib\T&DT.&UT.H&DH.&UH.Y;";

Solution
‎01-27-2016 11:26 AM
Super User
Posts: 5,498

Re: How to change directory name automaticly

[ Edited ]

You will need to move the %LET statements so that they come before the directory path:

 

%let DT=90;

%let UT=99;

%let DH=01;

%let UH=03;

 

%let dir2=M:\Lib\T&DT.&UT.H&DH.&UH.Y_CO;

libname coeficents "&dir2";

 

It's not clear from your post whether these are the exact changes to make to the directory path, but this gives you the technique to apply.

 

Good luck.

Contributor Moh
Contributor
Posts: 20

Re: How to change directory name automaticly

Posted in reply to Astounding

It's not working !!!!

Super User
Posts: 5,498

Re: How to change directory name automaticly

This is a short enough program that you should be able to post your program and the log from it.

Super User
Posts: 19,770

Re: How to change directory name automaticly

That's too bad....but we have no idea what that means. 

Super User
Posts: 11,343

Re: How to change directory name automaticly

Did you change the LIBNAME to 8 characters?

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 273 views
  • 0 likes
  • 4 in conversation