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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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