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!!!

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
  • 2 replies
  • 725 views
  • 0 likes
  • 2 in conversation