Edit

SAS: Sample PGM for person*year for AE

  This is a sample program for calculating a person-year by each preferred term of adverse event (AE).  Suppose that there are two data-sets for date of completion/discontinuation (#1) and for AEs with preferred term (PT) and start date (#2).  The person-year will be the sum of days until the start date for first AE from first dosing of each subject.  If a subject does not have any AE during a study, completion date or discontinuation date will be used.

  In the following sample data set, five subjects from ID=1 through ID=5 are included.  ID=3 had two PT with 'A' and 'B.' that occurred in different date.  ID=1, 2, 4, and 5 completed the study, but ID=3 discontinued at day 50 from first dosing. 

This is the sample program I asked in some Japanese bulletin board (データステップ100万回掲示板) where the source is Here.        


PROGRAM 
--------------------------------------
*--------------------------------------
SAMPLE PGM:
TO CALCULATE PERSON*YEAR BY SUBJECTS
--------------------------------------- 
OUTPUT I want to have.
  TOTAL A=100+100+10+100+100
  TOTAL B=100+100+20+100+100
  TOTAL C=100+100+50+ 10+100

*--------------------------------------;
DATA DC; ** #1 **;
INPUT SUBJECT $ DAY ;
CARDS ;
1 100
2 100
3 50
4 100
5 100
;
 

RUN ;

DATA AE;** #2 **;
INPUT SUBJECT $ PT $ DAY ;
CARDS ;
3 A 10
3 B 20
4 C 10
;
 

RUN ;

********************************************
EXTRACT PT
********************************************;
 

PROC SORT DATA=AE OUT=AE2(KEEP=PT) NODUPKEY ;
  BY PT ;
  WHERE PT^="" ;
RUN ;

 
********************************************
CARTESIAN PRODUCT: SUBJECT BY PT
********************************************;
 

PROC SQL ;
 CREATE TABLE ALL AS
 SELECT DC.SUBJECT, AE2.PT, DC.DAY
 FROM DC, AE2
 ORDER BY DC.SUBJECT, E2.PT
; 

QUIT ;
 
********************************************
OVERWRITE
********************************************;
 

DATA ALL2 ;
 MERGE ALL AE;
    BY SUBJECT PT ;
RUN ;

 
 ********************************************
SUMMARY BY PT
********************************************;
 

PROC SUMMARY DATA=ALL2 ;
 CLASS PT ;
   VAR DAY;
 OUTPUT OUT=OUT4(WHERE=(_TYPE_ NE 0)) SUM(DAY)=TOTAL ;
RUN ;

PROC PRINT DATA=OUT4 ;
RUN ;

--------------------------------------  



OUTPUT 



 

Search This Blog