LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2008, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 20 May 2008 09:23:58 -0400
Reply-To:     "Long, Stuart (NIH/NIEHS) [C]" <long3@NIEHS.NIH.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Long, Stuart (NIH/NIEHS) [C]" <long3@NIEHS.NIH.GOV>
Subject:      Re: Easy question - Data step processing
Comments: To: sas 9 bi user <sas9bi@GMAIL.COM>
In-Reply-To:  A<af7d406c0805192045l78552cfw48f46efa5716e779@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"

DATA have; INPUT member_id month value ; key_var=_N_; cards; 1 1 0 1 3 1 1 3 4 1 3 8 1 12 10 2 1 0 2 1 2 2 9 22 2 9 5 2 9 17 ;

PROC SORT DATA=have; BY member_id month DESCENDING value; RUN;

DATA need; SET have; BY member_id month ; RETAIN bad_event 0; IF first.month & value>7 THEN bad_event = 1; ELSE IF first.month & value<=7 THEN bad_event = 0;

RUN;

/* now if you want to have your data set back in the original order, do this sort */ PROC SORT DATA=need OUT =need(DROP = key_var); BY key_var; RUN;

PROC PRINT DATA=need; RUN;

-----Original Message----- From: sas 9 bi user [mailto:sas9bi@GMAIL.COM] Sent: Monday, May 19, 2008 11:46 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Easy question - Data step processing

/* All say I have the below. Suppose if in a given month, the a member's Value (see below) is >7. In that case I flag it as a "bad event". Bad event = value >7.

My question is, if there is a "bad event" in a given month, how to I flag the whole month as having a "bad event"? See below, it should make more sense. Thanks in advance for your wisdom...

*/

data a; input member_id month value ; cards; 1 1 0 1 3 1 1 3 4 1 3 8 1 12 10 2 1 0 2 1 2 2 9 5 2 9 17 ; run;

proc sort data=a; by id month; run;

data b; set a; if value >7 then bad_event = 1; else bad_event =0; run;

proc print; run;

/* I want the final to look like this, basically, if a member has an event (value >7) then their flag for the whole month is YES (as indicated by the last column (bad_event_in_member-id_and_month?).

member_id month value bad_event bad_event_in_member-id_and_month? 1 1 0 0 NO 1 3 1 0 YES 1 3 4 0 YES 1 3 8 1 YES 1 12 10 1 NO 2 1 0 0 NO 2 1 2 0 NO 2 9 5 0 YES 2 9 17 1 YES

*/


Back to: Top of message | Previous page | Main SAS-L page