BookmarkSubscribeRSS Feed
Simi
Calcite | Level 5
Dear all,

I have a following problem. Suppose I have data in form of:

Failing for (in months) First Date of Fail
11 20APR2011
7 25OCT2011
2 08APR2011
3 13APR2011
3 26APR2011
6 02MAY2011
7 03MAY2011
6 11MAY2011

What I'm trying to achieve is to have a cumulative sum of 'Failings' by month and year, i.e. get columns in a form of
Year Month No. of Failed
2011 4 x
2011 5 y
etc.

It is easy to obtain cumulative sum of the column 'First Date of Fail', however I do not know how to incorporate the column 'Failing for (in months)' into the cumulative some (i.e. for the first observation, it will be counted as a fail for 11 months in the row including the first month of the fail)

Could anyone suggest an appropriate code or procedure in SAS?

Thank you,

Simi
2 REPLIES 2
Patrick
Opal | Level 21
Hope below code is appropriate.


data have;
infile datalines truncover dlm=' ';
input NoOfFailure:8. DateFirstFailure:date9.;
format DateFirstFailure date9.;
datalines;
11 20APR2011
7 25OCT2011
2 08APR2011
3 13APR2011
3 26APR2011
6 02MAY2011
7 03MAY2011
6 11MAY2011
;
run;

Data V_FailureByMonth(keep=YearMonthFailure) / view=V_FailureByMonth;
set have;
format YearMonthFailure yymon7.;
do i=0 to (NoOfFailure-1);
YearMonthFailure=intnx('month',DateFirstFailure,i,'b');
output;
end;
run;

proc freq data=V_FailureByMonth noprint;
table YearMonthFailure / outcum out=want(keep=YearMonthFailure cum_freq);
run;

proc print data=want;
run;


HTH
Patrick
Simi
Calcite | Level 5
Thanks a lot Patrick, that's exactly what I was after!!!
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1360 views
  • 0 likes
  • 2 in conversation