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

Hi,

 

I have a macro list with the names of 3 comapanies: A,B and C, and the variable for the compnies is "company"


for each company I would like to create a folder on my computer, and I use the following code:

 

data _null_;
do while &company ne ;
x "mkdir c:\test\&company";
end;
run;

 

 

On the other hand when I just do:

x "mkdir c:\test\A";
x "mkdir c:\test\B";
x "mkdir c:\test\C";

I get the 3 folders as wanted, so it seems that there is a problem with my iteration.

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
*Maybe you can skip the macro variable step, 
assuming you create it from a list of companies in a dataset;

data have; input company $; cards; A B C ; run; data new_dirs; set have; new_dir= dcreate(company, "C:\test\"); run;

View solution in original post

7 REPLIES 7
Reeza
Super User

Your loop is specified incorrectly. 

 

You can use dcreate as well, fyi. 

 

What does your macro variable look like, resolve to? I'm not sure how you expect it to loop. 

Reeza
Super User
*Maybe you can skip the macro variable step, 
assuming you create it from a list of companies in a dataset;

data have; input company $; cards; A B C ; run; data new_dirs; set have; new_dir= dcreate(company, "C:\test\"); run;
ilikesas
Barite | Level 11

Hi Reeza,

 

thnka sfor the code, I ran it but the column "new_dir" that it created was empty (and no new folders...).

 

Initially I had a data set "test" with many lines per company, then I extracted the unique comany names witht he following code:

 

proc sql noprint;
create table companies as select distinct company into: cmlst separated by ' ' from test;
quit;

And then I did the my code...

 

Thanks!

Reeza
Super User

Post post your code and log. 

 


proc sql noprint;
create table companies as select distinct company from test;
quit;

Data want; 
Set companies; 
New_dir=Dcreate(company, 'C:\test\');
Run;  

Also check your folder to see if they're created. 

 

ilikesas
Barite | Level 11

Hi Reeza,

 

I am getting very weired results:

 

Once I tried your sample code when the 3 companies were written in a data step and actually got the 3 folders!!! (and the paths to the directories were included in the new_dir).

 

Then I wanted to do the same thing with my data but didn't get anything (and the new_dir is empty), and when wanted to re do your sample code also didn't get anything! There is no error message whatsoever.

???

 

Thanks!

Reeza
Super User

No, there is no,error message. Read the doc regarding the function. 

 

If your having issues you can use call system instead and build file path using CAT functions. 

 

If the folder already exists they won't get overwritten. 

ilikesas
Barite | Level 11

Hi Reeza,

 

sorry for being so confusing but now it works all the time!!!

 

Its just that I realized that the directory "test" must already exist in order for the other directories to be put into it.

 

Last time when your sample code worked and I wanted to redo it on my company data I actually deleted the "test" directory (which somehow I had from previous attempts) in order to see how the code fully works, and that's when I wasn't getting anything becasue from what now I understand the function DECREATE must be given a parent directory since it doesn't create the "full path" but rather only the "end of the line" directory.

 

Thank you for your help and for making me discover DECREATE!!! 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 5958 views
  • 4 likes
  • 2 in conversation