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
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
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:
filename SPFinit url "https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas";
%include SPFinit; /* enable the framework */
filename packages "</your/directory/for/packages/>";
%installPackage(SPFinit macroArray)
filename packages "</your/directory/for/packages/>";
%include packages(SPFinit.sas);
%loadPackage(packageName)
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");
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
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.