11-26-2014 11:13 AM
I have sort of a generalized question, if what I'm what I'm trying to do is possible then if it is possible I will work at it, just need to be pointed in the right direction...
What I want to do is based off of a certain ID in a sas table say "12ARBOB", or "34BXJIM" I want to run a macro based on the fourth character (R or X). If it is R then run macro A, if it is X then run macro B.
Secondly I would need "BOB" or "JIM" to become variables in the Macro that they run in.
Lastly, there are many ID's in this table so I would only want to grab a few based off of a calendar date that has it's own column in the same table as the ID's
I spent most of yesterday reading about array's and %Do statements, would that be the best route for this project? I've mostly only ever used Proc SQL in SAS so knowing where to start this project is a bit of a head scratcher.... Any direction would be greatly appreciated!
11-26-2014 11:19 AM
%macro a (param=); ...
%macro b (param=); ...
if substr(id,4,1)="R" then call execute('%a (param=BOB);');
else call execute('%b (param=JIM);');
However the real question is why you need to run different macros for different bits of data. As I always say, in 99% of the cases I come across, thinking about your data and what you want to do in different ways will eliminate the need for this type of operation anyway. An example:
Say I want to sum age for BOB records and sum height for JIM:
if index(id,"BOB")>0 then val=age;
create table RESULTS as
select distinct ID,
SUM(VAL) as RESULT
group by ID;
11-26-2014 11:54 AM
Thanks for the reply RW!
The reason why I would want to run different Macro's would be because the macros themselves are big pieces of code that create 30+ tables, so they are pretty granular. I've thought about what you mentioned though, and what would be the best route to work on this, and likely if I had taken on this project from the beginning I would not have written 7 different programs, but instead one program that has enough data steps in it to work.