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
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
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.
I think example is fine
great
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;
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.