Hi Everyone,
I have a FULL_data file in which each date has a number of characteristics.
I have another condition file that specifies condition for a give 2 characteristic value.
For any condition in condition file, I want to pull all date from FULL_data that meet this condition.
(in my real work, the condition could be 4 or 5 characteristics )
I don't know how to get that kind of merge.
Any help is very much appreciated.
HHC The WANT file
condition_ID
condt1
value1
cond2
value2
date
1
a
4
b
5
11
1
a
4
b
5
12
2
c
1
d
2
14
data FULLDATA; input date a b c d ; datalines; 11 4 5 1 1 12 4 5 2 5 13 4 1 2 6 14 8 3 1 2 ;run;
data condition; input condition_ID cond1 $ value1 cond2 $ value2; datalines; 1 a 4 b 5 2 c 1 d 2 ;run;
*************************
Also, I want to have the WANT file for all records that meet 1 of the 2 conditions (OR), please give me a hint if it is not long.
Thank you.
*After getting the condition-combination file,
this code will help to merge the condition-combination file with the Full data (retunr) file
In the output file, each condition has all record that meet it. and can be use to analyze quality of condition;
data FULLDATA;
input date a b c d ;
datalines;
11 4 5 1 1
12 4 5 2 5
13 0 1 2 2
14 8 5 1 2
20 4 5 1 2
;run;
data condition;
input condition_ID cond1 $ value1 cond2 $ value2;
datalines;
1 a 4 b 5
2 c 1 d 2
;run;
******************************************************************************************
*Combination of AND condition1 and condition2;
filename tmp temp;
data _null_;
set condition end=last_cond;
file tmp;
put 'if (' cond1 '=' value1 'AND ' cond2 '=' value2 ')'
' then do; condition_id=' condition_id '; output;end;' ;
*if last_cond=0 then put 'else';
run;
options source2;
data want_and;
set fulldata;
%include tmp;
run;
proc sort data=want_and; by condition_id date;run;
*look into the temfile, the second code is like that;
data want2;
set fulldata;
if (a =4 and b =5) then do; condition_id=1 ; output;end;
if (c =1 and d =2) then do; condition_id=2 ; output;end;
run;
******************************************************************************************
*Combination of OR condition1 and condition2;
filename tmp temp;
data _null_;
set condition end=last_cond;
file tmp;
put 'if (' cond1 '=' value1 'OR ' cond2 '=' value2 ')'
' then do; condition_id=' condition_id '; output;end;' ;
*if last_cond=0 then put 'else';
run;
options source2;
data want_or;
set fulldata;
%include tmp;
run;
proc sort; by condition_id date;run;
*look into the temfile, the second code is like that;
data want2;
set fulldata;
if (a =4 OR b =5) then do; condition_id=1 ; output;end;
if (c =1 OR d =2) then do; condition_id=2 ; output;end;
run;
proc sort; by condition_id date;run;
... View more