DATA Step, Macro, Functions and more

Deriving Epoch

Reply
Occasional Contributor
Posts: 14

Deriving Epoch

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.

 

THANKS

Super User
Posts: 8,066

Re: Deriving Epoch

select a.usubjid, a.date, b.epoch
from data_a a, data_b b
where a.usubjid = b.usubjid and b.startdate <= a.date <= b.enddate
;

In SAS proc sql

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 14

Re: Deriving Epoch

Posted in reply to KurtBremser
there is one problem for screening should be <= date< , for treatment <= date<=, and for follow up <date <=
Super User
Posts: 8,066

Re: Deriving Epoch

Then you Need to supply usable example datasets (in datasteps, see https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...). Post those datasteps according to https://communities.sas.com/t5/Getting-Started/How-to-add-SAS-syntax-to-your-post/ta-p/224394/jump-t....

Then also post a visual example of the result expected from those datasets.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Highlighted
Occasional Contributor
Posts: 14

Re: Deriving Epoch

Posted in reply to KurtBremser

I think example is fine

Super User
Posts: 8,066

Re: Deriving Epoch

Then I won't be able to help you.


Vahe_Mar wrote:

I think example is fine


 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 14

Re: Deriving Epoch

Posted in reply to KurtBremser

great

Occasional Contributor
Posts: 14

Re: Deriving Epoch

Posted in reply to KurtBremser

I 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;

Trusted Advisor
Posts: 1,068

Re: Deriving Epoch

@Vahe_Mar:

 

Your smug reply to @KurtBremser 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;

Ask a Question
Discussion stats
  • 8 replies
  • 124 views
  • 1 like
  • 3 in conversation