BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
anissak1
Obsidian | Level 7

Hello.  I have matched pairs of observations in a long form.  I want to create a new variable "Cohort Censor".

For each case (case=1), Cohort Censor should equal walkcensordate.  For each control (case=0), it should be the value of the case with that has same match number.  Short dataset attached.

This seems easy, but I'm still a relative neophyte and scratching my head how I can reference an indicator variable in a conditional way to create the new variable.

Thank you for any guidance

 

Anissa

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

One way to do this is with SQL:

 

proc sql;
create table forsas6 as
select *,
	(select walkCensorDate from forsas5 as b where b.matchNumber=a.matchNumber and b.case = 1) as cohortcensorDate 
from forsas5 as a;
quit;
PG

View solution in original post

4 REPLIES 4
anissak1
Obsidian | Level 7
I would like to clarify. Each control (case=0) should have a cohortcensor date that is the walkcensordate for its matched case (case=1).
PGStats
Opal | Level 21

One way to do this is with SQL:

 

proc sql;
create table forsas6 as
select *,
	(select walkCensorDate from forsas5 as b where b.matchNumber=a.matchNumber and b.case = 1) as cohortcensorDate 
from forsas5 as a;
quit;
PG
anissak1
Obsidian | Level 7
Thank you for this code! It worked perfectly. I don’t knOw SQL, but learned a bit from this example. :). Much appreciated!
sustagens
Pyrite | Level 9
proc sql;
create table want as 
select t1.*,
(case when t1.case=1 then t1.walkcensordate else t3.walkcensordate end) as cohortcensor
from forsas5 t1 
left join (select t2.* from forsas5 t2 where t2.case=1) t3 
on t1.matchnumber=t3.matchnumber;
quit;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 654 views
  • 2 likes
  • 3 in conversation