BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
asinusdk
Calcite | Level 5
yearidcensor
200111
200211
200311
200411
200511
200611
200220
200320
200420
200520
200620
200230
200330
200430
200530
200241
200341
200441
   

From this table, to make a table below,

 

yearidcensory01y02y03y04y05y06outcome
2001111000000
2002110100000
2003110010000
2004110001000
2005110000100
2006110000010
2002200100000
2003200010000
2004200001000
2005200000100
2006200000011
2002300100000
2003300010000
2004300001000
2005300000101
2002410100000
2003410010000
200441000100

0

 



I tried to use array function, but it didn't work out well.

 

Could you please help me to make a code for this?

 

Thanks so much.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

I would guess:

 

data have;
input year	id	censor;
datalines;
2001	1	1
2002	1	1
2003	1	1
2004	1	1
2005	1	1
2006	1	1
2002	2	0
2003	2	0
2004	2	0
2005	2	0
2006	2	0
2002	3	0
2003	3	0
2004	3	0
2005	3	0
2002	4	1
2003	4	1
2004	4	1
;

data want;
set have; by id;
array y y01-y06;
do i = 1 to dim(y);
    y{i} = i = mod(year, 100);
    end;
outcome = last.id and not censor;
drop i;
run;

proc print data=want noobs; run;
PG

View solution in original post

4 REPLIES 4
Reeza
Super User
Please show what you've tried so far.
PGStats
Opal | Level 21

I would guess:

 

data have;
input year	id	censor;
datalines;
2001	1	1
2002	1	1
2003	1	1
2004	1	1
2005	1	1
2006	1	1
2002	2	0
2003	2	0
2004	2	0
2005	2	0
2006	2	0
2002	3	0
2003	3	0
2004	3	0
2005	3	0
2002	4	1
2003	4	1
2004	4	1
;

data want;
set have; by id;
array y y01-y06;
do i = 1 to dim(y);
    y{i} = i = mod(year, 100);
    end;
outcome = last.id and not censor;
drop i;
run;

proc print data=want noobs; run;
PG
Reeza
Super User
Index the array with the year?
novinosrin
Tourmaline | Level 20

Same idea as PG, but easier than having to use mod

 


data want;
set have; 
by id;
array y(2001:2006) y01-y06;
do i = lbound(y) to hbound(y);
    y{i} = i = year;
end;
drop i;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 829 views
  • 2 likes
  • 4 in conversation