BookmarkSubscribeRSS Feed
RandyStan
Fluorite | Level 6

Dear All

My data is as follows.  On July 3 2020 VariableC should restatrt the Aggregation

 

DATE                    Time            VariableA            VariableB           Var_AGG

01JAN2020          9:30:05              B                      100                      100

01JAN2020           9:30:08             S                        25                         75

02JAN2020          10:45:45            S                        25                         50

02JAN2020           11:26:13           B                        35                         85

03JUL2020         13:15:58             B                        205                      205

03JUL2020          13:45:08            S                           45                     160

 

On July 3 2020 VariableC should restatrt the Aggregation.  And the needed data is as follows

DATE                    Time            VariableA            VariableB           Var_AGG

01JAN2020          9:30:05              B                      100                      100

01JAN2020           9:30:08             S                        25                         75

02JAN2020          10:45:45            S                        25                         50

02JAN2020           11:26:13           B                        35                         85

03JUL2020         13:15:58             B                        205                      205

03JUL2020          13:45:08            S                           45                     160

 

Can someone please help.  Thank you in advance.

   Randy

5 REPLIES 5
art297
Opal | Level 21

What is the rule that determines when aggregation should restart?

 

Art, CEO, AnalystFinder.com

 

RandyStan
Fluorite | Level 6

On the date; July 3, 2020 (03JUL2020)

art297
Opal | Level 21

Seems too determined to be realistic, but the following would meet your condition:

data want;
  set have;
  by date;
  if _n_ eq 1 or (date eq '03JUL2020'd and lag(date) ne '03JUL2020'd) then Var_AGG=0;
  if VariableA='B' then Var_AGG+VariableB;
  else Var_AGG+-1*VariableB;
run;

Art, CEO, AnalystFinder.com

 

RandyStan
Fluorite | Level 6

Yes that is true.  The reason is a quarters worth of missing data and the data is again available after a quarter.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 5 replies
  • 685 views
  • 0 likes
  • 3 in conversation