Data one;
input censored time;
cards;
0 1
0 2
1 2
0 4
1 5
0 6
0 9
1 10
; run;
Data one; set one; ord=_N_;
run;
%let num=8;
proc transpose data=one out=t1;
ID ord; var time; run;
Data t1; set t1; rename _1-_&num=t1-t# run;
proc transpose data=one out=t2;
ID ord; var censored; run;
Data t2; set t2; rename _1-_&num=c1-c# run;
Data two; merge t1 t2; run;
data cal1;
set two; array t (8) t1-t# array c (8) c1-c# array v (8) v1-v#
do i=1 to &num-1;
v=0;
if c=0 then v=t;
if c=1 then do j=i+1 to # v=t
end;
v[&num]=t[&num]; keep v1-v#
run;
Data te;
set cal1; array v (8) v1-v#
do i=1 to #
times=v; output; end; keep times; run;
Data te; set te; ord=_N_; run;
Data final; merge one te ; by ord; drop ord; run;
proc print data=final;
run;
1 | 0 | 1 | 1 |
2 | 0 | 2 | 2 |
3 | 1 | 2 | 34 |
4 | 0 | 4 | 4 |
5 | 1 | 5 | 25 |
6 | 0 | 6 | 6 |
7 | 0 | 9 | 9 |
8 | 1 | 10 | 10 |
How can I modify the code to do the same thing but by strata.
Thant’s
Data one;
input censored time strata;
cards;
0 1 1
0 2 1
1 2 1
0 4 1
1 5 1
0 6 1
0 9 1
1 10 1
0 1 2
0 2 2
1 2 2
0 4 2
1 5 2
0 6 2
0 9 2
1 10 2
Create same data as above but by strata.
How can I modify the above code to do this.
Very similar to the first case but this is by strata.
1 | 0 | 1 | 1 1 |
2 | 0 | 2 | 1 2 |
3 | 1 | 2 | 1 34 |
4 | 0 | 4 | 1 4 |
5 | 1 | 5 | 1 25 |
6 | 0 | 6 | 1 6 |
7 | 0 | 9 | 1 9 |
8 | 1 | 10 | 1 10 |
1 | 0 | 1 | 2 1 |
2 | 0 | 2 | 2 2 |
3 | 1 | 2 | 2 34 |
4 | 0 | 4 | 2 4 |
5 | 1 | 5 | 2 25 |
6 | 0 | 6 | 2 6 |
7 | 0 | 9 | 2 9 |
8 | 1 | 10 | 2 10 |
|
If you only have two strata's there's no point. Copy and paste the code twice and implement a WHERE clause on the data. Otherwise it's probably worth you trying it first.
ie
Data one;
set one;
WHERE STRATA=1;
ord=_N_;
run;
*rest of code;
*Save final dataset;
Data final1; merge one te ; by ord; drop ord; run;
Data one;
set one;
WHERE STRATA=2;
ord=_N_;
run;
*rest of code;
*Save final dataset;
Data final2; merge one te ; by ord; drop ord; run;
*Append datasets;
data final;set final1 final2;
run;
Either add in a bunch of BY statements to the relevant procs, using first/last to initialize arrays as needed
OR create a macro to run each strata at a time.
I do not know how to do any, can you show me how to use a macro and by statement. I love macro and learning everyday
If you only have two strata's there's no point. Copy and paste the code twice and implement a WHERE clause on the data. Otherwise it's probably worth you trying it first.
ie
Data one;
set one;
WHERE STRATA=1;
ord=_N_;
run;
*rest of code;
*Save final dataset;
Data final1; merge one te ; by ord; drop ord; run;
Data one;
set one;
WHERE STRATA=2;
ord=_N_;
run;
*rest of code;
*Save final dataset;
Data final2; merge one te ; by ord; drop ord; run;
*Append datasets;
data final;set final1 final2;
run;
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.