Prev: macro %StrSrch
Next: export SAS graph into PowerPoint
From: jiji on 1 Mar 2010 16:58 Hello, So I have a longitudinal dataset with multiple observations. One variables is whether subject had surgery at a certain time point: character categorical variable (Yes, No). So the observation is Y if the person had surgery and the rest are N. Since I do not want to look at independent variables after surgery. I want to delete all rows after the variable hits a Y. observations are coded as N after surgery, as such if a Y is recorded I would like to delete that along with the N at the rest of the time points for a certain subject. Please look at how it looks below: subject sx 1 N 1 N 1 Y how to Delete rows from here on for subject 1 1 N 1 N 2 N 2 Y how to Delete rows from here on for subject 2 2 N 3 N 3 N 3 Y how to Delete rows from here on for subject 3 3 N 3 N
From: Lou on 1 Mar 2010 19:59 "jiji" <joelleahallak(a)gmail.com> wrote in message news:c97d19f4-cbec-444f-927b-c7a444479944(a)x22g2000yqx.googlegroups.com... > Hello, > > So I have a longitudinal dataset with multiple observations. > One variables is whether subject had surgery at a certain time point: > character categorical variable (Yes, No). > So the observation is Y if the person had surgery and the rest are N. > > Since I do not want to look at independent variables after surgery. I > want to delete all rows after the variable hits a Y. observations are > coded as N after surgery, as such if a Y is recorded I would like to > delete that along with the N at the rest of the time points for a > certain subject. Please look at how it looks below: > > subject sx > 1 N > 1 N > 1 Y how to Delete rows from here on for subject 1 > 1 N > 1 N > 2 N > 2 Y how to Delete rows from here on for subject 2 > 2 N > 3 N > 3 N > 3 Y how to Delete rows from here on for subject 3 > 3 N > 3 N Presumably, your data are sorted by subject and timepont. In that case, something like this (untested) code should do: data fee; set fie; by subject; if first.subject then dleet = 0; if sx = 'Y' then dleet = 1; if dleet then delete; run;
From: Arthur Tabachneck on 1 Mar 2010 20:03 There is probably an easier way, but I think that the following will do what you want: data have; input subject sx $; cards; 1 N 1 N 1 Y 1 N 1 N 2 N 2 Y 2 N 3 N 3 N 3 Y 3 N 3 N ; data want; set have; retain keep_going; by subject; if first.subject then keep_going=1; if keep_going eq 1 then output; if trim(left(sx)) eq "Y" then keep_going=0; run; HTH, Art ------------- On Mar 1, 4:58 pm, jiji <joelleahal...(a)gmail.com> wrote: > Hello, > > So I have a longitudinal dataset with multiple observations. > One variables is whether subject had surgery at a certain time point: > character categorical variable (Yes, No). > So the observation is Y if the person had surgery and the rest are N. > > Since I do not want to look at independent variables after surgery. I > want to delete all rows after the variable hits a Y. observations are > coded as N after surgery, as such if a Y is recorded I would like to > delete that along with the N at the rest of the time points for a > certain subject. Please look at how it looks below: > > subject sx > 1 N > 1 N > 1 Y how to Delete rows from here on for subject 1 > 1 N > 1 N > 2 N > 2 Y how to Delete rows from here on for subject 2 > 2 N > 3 N > 3 N > 3 Y how to Delete rows from here on for subject 3 > 3 N > 3 N
From: NordlDJ on 1 Mar 2010 20:52 > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Lou > Sent: Monday, March 01, 2010 5:00 PM > To: SAS-L(a)LISTSERV.UGA.EDU > Subject: Re: How to delete rows in a sas dataset > > "jiji" <joelleahallak(a)gmail.com> wrote in message > news:c97d19f4-cbec-444f-927b- > c7a444479944(a)x22g2000yqx.googlegroups.com... > > Hello, > > > > So I have a longitudinal dataset with multiple observations. > > One variables is whether subject had surgery at a certain time point: > > character categorical variable (Yes, No). > > So the observation is Y if the person had surgery and the rest are N. > > > > Since I do not want to look at independent variables after surgery. I > > want to delete all rows after the variable hits a Y. observations are > > coded as N after surgery, as such if a Y is recorded I would like to > > delete that along with the N at the rest of the time points for a > > certain subject. Please look at how it looks below: > > > > subject sx > > 1 N > > 1 N > > 1 Y how to Delete rows from here on for subject 1 > > 1 N > > 1 N > > 2 N > > 2 Y how to Delete rows from here on for subject 2 > > 2 N > > 3 N > > 3 N > > 3 Y how to Delete rows from here on for subject 3 > > 3 N > > 3 N > > Presumably, your data are sorted by subject and timepont. In that case, > something like this (untested) code should do: > > data fee; > set fie; > by subject; > if first.subject then dleet = 0; > if sx = 'Y' then dleet = 1; > if dleet then delete; > run; You will need to add a retain statement to the data step (add it anywhere); retain dleet; Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204
From: Mike Zdeb on 2 Mar 2010 08:49 hi ... yet another idea (with the no+1 versus no=1, you can leave out the RETAIN statement) ... data x; input subject sx : $1.; datalines; 1 N 1 N 1 Y 1 N 1 N 2 N 2 Y 2 N 3 N 3 N 3 Y 3 N 3 N ; run; data y; set x; by subject; if first.subject then no=0; if sx eq 'Y' then no+1; if ^no; drop no; run; -- Mike Zdeb U(a)Albany School of Public Health One University Place Rensselaer, New York 12144-3456 P/518-402-6479 F/630-604-1475 > Hello, > > So I have a longitudinal dataset with multiple observations. > One variables is whether subject had surgery at a certain time point: > character categorical variable (Yes, No). > So the observation is Y if the person had surgery and the rest are N. > > Since I do not want to look at independent variables after surgery. I > want to delete all rows after the variable hits a Y. observations are > coded as N after surgery, as such if a Y is recorded I would like to > delete that along with the N at the rest of the time points for a > certain subject. Please look at how it looks below: > > subject sx > 1 N > 1 N > 1 Y how to Delete rows from here on for subject 1 > 1 N > 1 N > 2 N > 2 Y how to Delete rows from here on for subject 2 > 2 N > 3 N > 3 N > 3 Y how to Delete rows from here on for subject 3 > 3 N > 3 N >
|
Pages: 1 Prev: macro %StrSrch Next: export SAS graph into PowerPoint |