BookmarkSubscribeRSS Feed
melhaf
Fluorite | Level 6

Hi, 
I wanna create multiples folders within tow other folders like:
Path = C:\store\

PathFruits: '&Path.\fruit\<all kinds>

PathVegetables: '&Path\veg\<all kind>

 

where <all kinds fruits> goes from |apples , |orange, |pinapple|

and where <all kinds veggies> goes from | cucumber , | salad , | tomato |

 

intestead of doing the per row, repeating it? 
PathFruits: '&Path.\fruit\apples

'&Path.\fruit\orang

,.....,

'&Path.\fruit\veggies\tomato 

I have like,, 10*2 => 20 rows of this, and I think it is just ugly xD 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

It's really unclear to me what you are doing, its unclear to me what your question is, and its also unclear to me where your data is that you are working from.


In addition to writing a much more clear problem statement, could you please show us the data you are working from? Thanks

--
Paige Miller
melhaf
Fluorite | Level 6
Sorry, konfidential. Was trying to do it more 'univarsal'
yabwon
Onyx | Level 15

I would go with the macroArray package:

filename packages "C:\SAS_WORK\SAS_PACKAGES";
%include packages(SPFINIT.sas);

%loadPackage(macroArray)


/* set macro arrays */
%array(store[*] fruits veggies, vnames=Y, macarray=Y)
%array(fruits[*] apples orange pinapple, vnames=Y, macarray=Y)
%array(veggies[*] cucumber salad tomato, vnames=Y, macarray=Y)


options DLcreateDIR;
%let path = R:\store\;
libname _ "&path.";
libname _ list;

/* make store level dirs */
%do_over(store, phrase=%nrstr(
 libname _ "&path.\%store(&_i_)";
 libname _ list;
))

/* make fruits */
%do_over(fruits, phrase=%nrstr(
 libname _ "&path.\%store(1)\%fruits(&_i_)";
 libname _ list;
))

/* make veggies */
%do_over(veggies, phrase=%nrstr(
 libname _ "&path.\%store(2)\%veggies(&_i_)";
 libname _ list;
))

Bart

 

 

P.S. To install and use macroArray package do:

  • Enable the framework [first time only]:
  • filename SPFinit url "https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas";
    %include SPFinit; /* enable the framework */
  • Install the framework and the package on your machine in the folder you created:
  • filename packages "</your/directory/for/packages/>"; 
    %installPackage(SPFinit macroArray) 
  • From now on, in your SAS session just run it like this:
  • filename packages "</your/directory/for/packages/>";
    %include packages(SPFinit.sas);
    
    %loadPackage(packageName)  

Link to details.

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



A_Kh
Lapis Lazuli | Level 10

If your aim is creating multiple directories (including subfolders) to store datasets, use LIBNAME statement with sas system option dlcreatedir:

options dlcreatedir;
	*multiple statements; 
	libname fruits "C:\store\fruit";
	libname fruits "C:\store\fruit\apples";
	libname fruits "C:\store\fruit\orange";

	libname veggies "C:\store\veg";
	libname veggies "C:\store\veg\tomato";
	libname veggies "C:\store\veg\cucumber";

	*single statement; 
	libname folders ("&path.\fruit", "&path.\fruit\apples", "&path.\fruit\orange", "&path.\fruit\bananas"); 
yabwon
Onyx | Level 15

Good point to make it with 1 LIBNAME statement!

 

Version with macro arrays:

options DLcreateDIR;
%let path = R:\store\;
libname _ 
(
"&path."

/* make store level dirs */
%do_over(store, phrase=%nrstr(
"&path.\%store(&_i_)"
))

/* make fruits */
%do_over(fruits, phrase=%nrstr(
"&path.\%store(1)\%fruits(&_i_)"
))

/* make veggies */
%do_over(veggies, phrase=%nrstr(
"&path.\%store(2)\%veggies(&_i_)"
))

);
libname _ list;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SASKiwi
PROC Star

Why do you want to split your SAS data into separate folders based on fruit and vegetable type? It would be a whole lot easier just to have one folder and have one type per dataset, or even better just have multi-type datasets with a column identifying the fruit or vegetable type.

 

All you are doing is making your programming a lot harder than it needs to be. 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 995 views
  • 0 likes
  • 5 in conversation