I am trying to compare the data present in the folder ( which check for latest data). I am running the macro to do this but I believe, I am not doing the efficient way. I have the folder structure like mentioned in the image ( Tried approximately to match my expectation). So I am expecting to check what States ( Folder names) present in the 'Expens-2022' and create a macro variables and compare that with the same state folders present in the 'Doc ' Folder instead checking the Expens-2022' folder and entering each state name while calling the macro. I do have the macro '%expense which do the job. But how to achieve this instead. I am trying to control the State macro variable ( if it makes any sense.) Thanks for your input.. Thank you for your input.
%expnse(state= , prv= );
--------
----------
-----------
%mend;
%expense(state= NJ, prv= DOC);
%expense(state= MA, prv= DOC);
%expense(state= NY, prv= DOC);
Do you have list of the states? If not then perhaps you can use the FIPSTATE() function to generate the list.
data _null_;
do fip=1 to 56 ;
state = fipstate(fip);
if state ne '--' then do;
call execute(cats('%nrstr(%expense)(state=',state,',prv=DOC)'));
end ;
end;
run;
Do you have list of the states? If not then perhaps you can use the FIPSTATE() function to generate the list.
data _null_;
do fip=1 to 56 ;
state = fipstate(fip);
if state ne '--' then do;
call execute(cats('%nrstr(%expense)(state=',state,',prv=DOC)'));
end ;
end;
run;
Thank you Tom. It kind worked. I used the concept from your code. However got a question FIPstate creates the list of states. What's situation if the folder names are different?
There are lots of ways to ask the operating system what files and directories exist.
Here is one that will span a whole sub-tree of the directory and collect all of the folders.
https://github.com/sasutils/macros/blob/master/dirtree.sas
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.