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 ;
--------------------------------------
Post a Comment
別ページに移動します