07-05-2013 09:42 AM
Getting a little rusty with coding since I spend too much time in DIS. ;-) I have the following problem (only because that's the way I chose to solve the task I have to fix).
I am reading a dataset_1 (account = key) and depending on the value of some variables on certain observations I need to check another dataset_2 if this account is found there.
If so, I need to do some calculations for this account and finish with deleteíng the observation i dataset-2.
Does this makes sense? I tried with a macro but that didn't work. Not the way I used it anyway.
Who likes to take up the challenge?
07-05-2013 10:01 AM
If I understand this right then it is about "how to implement conditional processing using DIS?".
What I've done in the past is to start a macro definition in the pre-code of the first node in the chain for conditional processing and then in the post-code of the last node for conditional processing end the macro and call it. If you need this more visible in the flow then you could also add user written code nodes at the beginning and the end of this sub-flow.
So "%macro DoSomething; %if <condition> %then %do;" in the pre-code of the first node, and "%end; %mend; %DoSomething;" in the post-code of the last node.
Reading Quentin's answer I've realised that you're eventually just after some logic of how to code this. Under the assumption that your tables are stored in SAS below some code which is hopefully useful for you.
do account_nr=10 to 15;
set dataset_1 end=last;
if _n_=1 then
declare hash h1 (dataset:'dataset_2');
declare hash Hdel ();
if h1.check()=0 then
/* here some calculations */
/* collect account_nr to be deleted */
if last then
delete from dataset_2
where account_nr in (select account_nr from deletes)
07-05-2013 11:59 AM
I'm not sure I follow. If you are planning to write the code yourself, you might code it as:
1. Subset the dataset_1 to identify all the account numbers you want to check for in dataset_2.
2. Merge the subset-ed dataset_1 and dataset_2 to identify which of those accounts exist in dataset_2, then do your calculcations / deletetions etc
Doesn't sound like a macro or %INC problem to me. Sounds more like SQL or DATA step progrmming. If you are having problems with the programming, might help to show a few sample records from dataset_1 and dataset_2, and describe your desired output.
07-08-2013 03:26 AM
Quentin and Patrick! Thanx for your input! I will try to see if I can use the information/examples you sent me. A SAS consultant one told me I should look into hash coding. Didn't manage to get there yet. Maybe about time ...
If I cannot make it work I will send you the programs I wrote and tell you what output I look for. For now, once again: THANX! :smileygrin:
/ Menno (a.k.a. Longimanus)