Hi All,
this is my part of dataset
SUBJID PSADN days pcfn
70007 08DEC2008 -8 .
70007 15DEC2008 -1 .
70007 05JAN2009 21 1.2
70007 26JAN2009 42 -16.7
70007 23FEB2009 70 -10.6
70007 16MAR2009 91 47.1
70007 06APR2009 112 32.0
70007 28APR2009 134 8.2
70007 18MAY2009 154 46.1
70007 08JUN2009 175 39.6
70007 29JUN2009 196 55.0
70007 20JUL2009 217 51.8
70007 08SEP2009 267 149.9
70007 28SEP2009 287 1 114.5
i have to pick only those records which having pcfn>25. if pcfn>25 , in next records also it is greater than 25 . In the above example 16MAR2009 pcfn value is 47.1 but later the subject at 18may2009 he had <25 . So i dont want to consider those 2 records also. My final o/p be like
SUBJID PSADN days pcfn newdate flag
70007 18MAY2009 154 46.1 18MAY2009 1
70007 08JUN2009 175 39.6 18MAY2009 0
70007 29JUN2009 196 55.0 18MAY2009 0
70007 20JUL2009 217 51.8 18MAY2009 0
70007 08SEP2009 267 149.9 18MAY2009 0
70007 28SEP2009 287 1 114.5 18MAY2009 0
Thanks in advance!!!!!!!!
hi ... one idea ...
data x;
input subjid :$5. psadn :date9. days pcfn;
datalines;
70007 08DEC2008 -8 .
70007 15DEC2008 -1 .
70007 05JAN2009 21 1.2
70007 26JAN2009 42 -16.7
70007 23FEB2009 70 -10.6
70007 16MAR2009 91 47.1
70007 06APR2009 112 32.0
70007 28APR2009 134 8.2
70007 18MAY2009 154 46.1
70007 08JUN2009 175 39.6
70007 29JUN2009 196 55.0
70007 20JUL2009 217 51.8
70007 08SEP2009 267 149.9
70007 28SEP2009 287 114.5
;
proc sort data=x;
by subjid days;
run;
data y;
do until (last.subjid);
set x (in=one) x;
by subjid;
if one and pcfn le 25 then call missing(newdate);
else
newdate = ifn(one and missing(newdate), psadn , newdate);
flag = psadn eq newdate;
if ^one and psadn ge newdate then output;
end;
format newdate date9.;
run;
subjid psadn days pcfn newdate flag
70007 18MAY2009 154 46.1 18MAY2009 1
70007 08JUN2009 175 39.6 18MAY2009 0
70007 29JUN2009 196 55.0 18MAY2009 0
70007 20JUL2009 217 51.8 18MAY2009 0
70007 08SEP2009 267 149.9 18MAY2009 0
70007 28SEP2009 287 114.5 18MAY2009 0
hi ... one idea ...
data x;
input subjid :$5. psadn :date9. days pcfn;
datalines;
70007 08DEC2008 -8 .
70007 15DEC2008 -1 .
70007 05JAN2009 21 1.2
70007 26JAN2009 42 -16.7
70007 23FEB2009 70 -10.6
70007 16MAR2009 91 47.1
70007 06APR2009 112 32.0
70007 28APR2009 134 8.2
70007 18MAY2009 154 46.1
70007 08JUN2009 175 39.6
70007 29JUN2009 196 55.0
70007 20JUL2009 217 51.8
70007 08SEP2009 267 149.9
70007 28SEP2009 287 114.5
;
proc sort data=x;
by subjid days;
run;
data y;
do until (last.subjid);
set x (in=one) x;
by subjid;
if one and pcfn le 25 then call missing(newdate);
else
newdate = ifn(one and missing(newdate), psadn , newdate);
flag = psadn eq newdate;
if ^one and psadn ge newdate then output;
end;
format newdate date9.;
run;
subjid psadn days pcfn newdate flag
70007 18MAY2009 154 46.1 18MAY2009 1
70007 08JUN2009 175 39.6 18MAY2009 0
70007 29JUN2009 196 55.0 18MAY2009 0
70007 20JUL2009 217 51.8 18MAY2009 0
70007 08SEP2009 267 149.9 18MAY2009 0
70007 28SEP2009 287 114.5 18MAY2009 0
one way:
data have;
infile cards missover;
input SUBJID PSADN $ days pcfn;
cards;
70007 08DEC2008 -8 .
70007 15DEC2008 -1 .
70007 05JAN2009 21 1.2
70007 26JAN2009 42 -16.7
70007 23FEB2009 70 -10.6
70007 16MAR2009 91 47.1
70007 06APR2009 112 32.0
70007 28APR2009 134 8.2
70007 18MAY2009 154 46.1
70007 08JUN2009 175 39.6
70007 29JUN2009 196 55.0
70007 20JUL2009 217 51.8
70007 08SEP2009 267 149.9
70007 28SEP2009 287 114.5
;
data temp;
set have;
by subjid;
if first.subjid then group+1;
if not first.subjid and pcfn>25 and lag(pcfn)<=25 then group+1;
run;
proc sql;
create table want as
select * from temp
where group in (
select group from temp
group by group
having min(pcfn)>25);
quit;
proc print;run;
Thanks to you both!!!!!!!
Hi LinLin your apporach is good
Hi mike,
I got what i want but i have small question
what does it mean "Interleaving a Dataset with Itself' ?
could you explain little bit
Did you read the article that Mike mentioned in your previous thread? i.e.:
ps "Interleaving a Dataset with Itself: How and Why" by Howard Schreier
http://www.nesug.org/proceedings/nesug03/cc/cc002.pdf
It does a nice job of explaining the process.
Hi ... as Art said, Howard's article is great.
Quickly, "official" definition of INTERLEAVE ...
Howard explains all this in his paper (it was the first place I saw anyone interleave a data set with itself ... among the many things I have learned from Howard's paper, talks, and postings).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.