SAS中文论坛

标题: example using FIRST. and LAST. Variables [打印本页]

作者: shiyiming    时间: 2005-10-19 16:00
标题: example using FIRST. and LAST. Variables
[code:1d5a8]************************************************;
*** File:  FIRSTLAST.sas                     ***;
*** example using FIRST. and LAST. Variables ***;
************************************************;

** step 1:  create data set with some **;
**          repeat subjects (SID)     **;
DATA TEMP1;
                 INPUT SID VISIT SCORE;
CARDS;
01 1 87
02 1 77
03 1 62
02 2 54
03 2 77
04 2 21
;
RUN;

** first sort by ID variable **;
PROC SORT DATA=TEMP1;
                    BY SID;
RUN;

** create subset with only 1 visit **;
DATA ONEVISIT;
           SET TEMP1;
            BY SID;
           IF FIRST.SID AND LAST.SID;  * selects only those with one
                                                                   * visit;
RUN;

PROC PRINT DATA=ONEVISIT;
TITLE1 'SUBJECTS WITH ONLY ONE VISIT';      
RUN;


** create subset with 2 visits **;
DATA TWOVISIT;
                 SET TEMP1;
      BY SID;
     IF FIRST.SID=0 or LAST.SID=0;        * selects with two visits;
RUN;

PROC PRINT DATA=TWOVISIT;
TITLE1 'BOTH VISITS FOR SUBJECTS WITH 2 VISITS';
RUN;[/code:1d5a8]




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2