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.

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