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

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+v; end;

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;


View solution in original post

3 REPLIES 3
Reeza
Super User

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.

desireatem
Pyrite | Level 9

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

Reeza
Super User

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;


sas-innovate-2024.png

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.

 

Register now!

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
  • 3 replies
  • 496 views
  • 0 likes
  • 2 in conversation