BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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 ).

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
sahoositaram555
Pyrite | Level 9

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 ).

PeterClemmensen
Tourmaline | Level 20

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 454 views
  • 1 like
  • 2 in conversation