Cumulative sum with time limitation

Reply
New Contributor
Posts: 3

Cumulative sum with time limitation

Sorry for asking a stupid question.

 

I have two data sets: A: with ID and date B: with ID newsnumber date. I would like to make data set C which includes the cumulative newsnumber by ID for the past 365 days prior to the date in data A. 

 

Thank you very much for your help.

 

PROC Star
Posts: 1,190

Re: Cumulative sum with time limitation

Post some sample of your data and what your desired output looks like Smiley Happy

New Contributor
Posts: 3

Re: Cumulative sum with time limitation

Data set A:

 

ID  Date

1    1998/07/21

2    2000/08/21

4    2001/04/21

6    1999/08/21

7    2000/06/21

9    2010/08/21

 

Data set B:

ID  Date Newsnumber

1

1

....

1

1

4    2000/04/22

4    2000/04/23

....

4    2000/06/22

4    2000/06/23

4    2000/06/24

...

4    2001/04/20

4    2001/04/21

6

6

6

...

6

6

6

 

For Data set C, let's take firm 4 for an example, I would like to get the cumulative sum of Newsnumber for the past 365 days before 2001/04/21.

 

Thanks~~~~ ^_^

Super User
Posts: 22,874

Re: Cumulative sum with time limitation

@Lipty Do you have SAS/ETS? If so, look into PROC EXPAND

New Contributor
Posts: 3

Re: Cumulative sum with time limitation

Yes, I have it and read it last night. But didn't know how to solve for the problem. Thank you

Super User
Posts: 22,874

Re: Cumulative sum with time limitation

Post what you've tried.

Super User
Posts: 9,611

Re: Cumulative sum with time limitation

Use the macro provided in https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... to convert your datasets to data steps, or write your own data steps that create example data.

Post the resulting code according to https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce (How can I add SAS syntax to a post?)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 6 replies
  • 122 views
  • 0 likes
  • 4 in conversation