If the first row for colon_res_bill=1, then I want all of the other colon_res_bill's for that study_id to also be 1.
How would I go about this?
This is what I have tried, but it is not working.
proc sort data=colon_auth_paid out=colon_auth_paid_sort;
by study_id descending colon_res_bill;
run;
data colon_paid_heirarchy1;
set colon_auth_paid_sort;
by study_id descending colon_res_bill;
if first.colon_res_bill=1 then colon_res_bill_final=1;
else colon_res_bill_final=0;
run;
In the future, please include data as SAS data step code. Do NOT include data as a screen capture.
This solution assumes the data set is properly sorted.
data want;
retain flag;
set have;
by study_id;
if first.study_id then flag=(colon_res_bill=1);
if flag=1 then colon_res_bill=1;
drop flag;
run;
In the future, please include data as SAS data step code. Do NOT include data as a screen capture.
This solution assumes the data set is properly sorted.
data want;
retain flag;
set have;
by study_id;
if first.study_id then flag=(colon_res_bill=1);
if flag=1 then colon_res_bill=1;
drop flag;
run;
Hi A_Halps
This can be achieved with the FIRST. & LAST. processing and the retain statement
Here's an example
data input ;
drop i ;
do study_id=1 to 3 ;
do i=1 to 5 ;
if i=1 and ranuni(1)>0.5 then
colon_res_bill=1 ;
else
colon_res_bill=0 ;
output ;
end ;
end ;
run ;
proc sort data=input out=srtd ;
by study_id ;
run ;
data results ;
retain retain_crb 0 ;
drop retain_crb ;
set srtd ;
by study_id ;
if first.study_id then
retain_crb=colon_res_bill ;
if retain_crb=1 then
colon_res_bill=1 ;
output ;
if last.study_id then
retain_crb=0 ;
run ;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.