@Vahe_Mar:
Your smug reply to @Kurt_Bremser in declining to provide a usable data set might be a little more sustainable if your solution below actually used variable names you provided in your original topic entry (also below). And there is nothing in the original post that would lead one to see a need for the LENGTH functions.
I'm glad you solved your problem, but it would be good for later viewers to see your proc sql code marked as the solution, and the problem description revised to make the solution apparent.
original message:
Hi All,
I need merge two datas, and take right variable from second data.
first one my main data , second one data which have 3 answers for every subject. how we can merge it using sql in sas or sas.
Example
DATA A DATA B
USUBJID DATE USUBJID STARTDATE ENDDATE EPOCH
1.001 10/10/17 1.001 09/10/17 14/10/17 SCREENING
2.001 15/10/17 15/12/17 TREATMENT
3.001 20/12/17 10/12/18 FOLLOW-UP
So need to check where is my date and take EPOCh for SCREENING for this example.
Your solution:
solved problem with this.
*Derive EPOCH*; proc sql noprint; create table epoch as select a.* ,b.epoch from faf1 as a left join sds.se as b on a.usubjid=b.usubjid and ( (length(a.FADTC)=10 and length(b.SESTDTC)=10 and b.SESTDTC<=a.FADTC) and (length(a.FADTC)=10 and length(b.SEENDTC)=10 and a.FADTC<=b.SEENDTC) and TAETORD =2 or (length(a.FADTC)=10 and length(b.SESTDTC)=10 and b.SESTDTC<=a.FADTC) and (length(a.FADTC)=10 and length(b.SEENDTC)=10 and a.FADTC<b.SEENDTC) and TAETORD =1 ) order by a.usubjid, a.facat, a.fascat, a.faobj ; quit;
... View more