Hi, i have a data set like below. fluidvalue is a numeric column having values xx, 0 and .(missing values) .for some patid's its not present. i tried doing it by retain statement. it works well if there is no .(missing value), but its stops counting especially by not considering the values after . (missing numeric dot).
data a;
input patid fluidvalue;
cards;
01001 30
01001 34
01001 0
01001 23
01001 .
01001 .
01001 .
01001 .
01001 80
01001 0
01002 .
01002 23
01002 34
01002 .
01002 45
01002 0
01002 .
01002 89
01002 0
01002 .
01003 23
01003 45
01003 45
01003 56
01003 90
01004 0
01004 90
01004 98
01004 23
01004 0
01005 0
01005 0
01005 0
01005 23
;
run;
data result;set a;
retain cum_EXDOSE;
if first.patid then cum_EXDOSE=fluidvalue;
else cum_EXDOSE=cum_EXDOSE+fluidvalue;
by patid;
run;
Please suggest how to do modification to this program to get the final output.I would like to solve it by using this retain statement, if possible . it would be better if someone suggests me if there is a way to get the final value next to patid across all the observations(if 01003 has 7 observation and the cum_EXDOSE is 120 then for every observation of 01003 , cum_EXDOSE will be 120 for all the rows of 01003 ).
I'm not entirely sure here, but I think this is what you want
data want;
do _N_ = 1 by 1 until (last.patid);
set a;
by patid;
sum_fluidvalue = sum(sum_fluidvalue, fluidvalue);
end;
do _N_ = 1 to _N_;
set a;
output;
end;
run;
Hi, i have a data set like below. fluidvalue is a numeric column having values xx, 0 and .(missing values) .for some patid's its not present. i tried doing it by retain statement. it works well if there is no .(missing value), but its stops counting especially by not considering the values after . (missing numeric dot).
data a;
input patid fluidvalue;
cards;
01001 30
01001 34
01001 0
01001 23
01001 .
01001 .
01001 .
01001 .
01001 80
01001 0
01002 .
01002 23
01002 34
01002 .
01002 45
01002 0
01002 .
01002 89
01002 0
01002 .
01003 23
01003 45
01003 45
01003 56
01003 90
01004 0
01004 90
01004 98
01004 23
01004 0
01005 0
01005 0
01005 0
01005 23
;
run;
data result;set a;
retain cum_EXDOSE;
if first.patid then cum_EXDOSE=fluidvalue;
else cum_EXDOSE=cum_EXDOSE+fluidvalue;
by patid;
run;
Please suggest how to do modification to this program to get the final output.I would like to solve it by using this retain statement, if possible . it would be better if someone suggests me if there is a way to get the final value next to patid across all the observations(if 01003 has 7 observation and the cum_EXDOSE is 120 then for every observation of 01003 , cum_EXDOSE will be 120 for all the rows of 01003 ).
Please do not double post. See my answer to your original post here
I'm not entirely sure here, but I think this is what you want
data want;
do _N_ = 1 by 1 until (last.patid);
set a;
by patid;
sum_fluidvalue = sum(sum_fluidvalue, fluidvalue);
end;
do _N_ = 1 to _N_;
set a;
output;
end;
run;
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 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.