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

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);

SASuserlot_0-1667401131664.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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;
Daryl
SAS Employee
I once wrote a SAS program that would shell out to the operating system, run an operating system directory listing to create a list of subdirectories in a folder (for example, in Windows:)
prompt:> cd C:\path\to\directory
prompt:> DIR *.
I may have redirected the output to a text file or somehow dumped the output (subdirectory names) into a SAS table, and then I just wrote a macro to iterate through the table of available directories. Looking for that code now but it might be gone.
SASuserlot
Barite | Level 11

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?

Tom
Super User Tom
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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