Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3699048
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:03:21+00:00 2026-05-19T05:03:21+00:00

I have a dataset as follows and I need to retrieve two things: 1)

  • 0

I have a dataset as follows and I need to retrieve two things: 1) the sum of VALUE between (date-1) and (date-3) for each date and 2) whether, during the 5 days, there are >= two days where the VALUE is 0. I think PROC SQL should be used but I’m not sure how to implement this.
INPUT DATASET:

ID   DATE      VALUE
1   20110101     0
1   20110102     0
1   20110103     1
1   20110104     2
2   20110101     1
2   20110102     2
2   20110103     3
2   20110104     4 

Output should be 1) 1 (0+0+1) for ID1, 20110104 and 6 (1+2+3) for ID2, 20110104. and 2) a mark for ID1, 20110104, since there are 2 days with a value of 0 during the 3-day window.

Any help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T05:03:22+00:00Added an answer on May 19, 2026 at 5:03 am

    Both problems can be solved with a similar SQL query. Your second question is a bit confusing, because you once mention a 5 day periode and once a 3 day window. I used the same 3 day window for both queries, so modify the start and end date if you need another window.

    1)

    proc sql;
     select t1.id, t1.date, sum(t2.value) as totalvalue
     from _input t1
     left join _input t2
     on t1.date-4 lt t2.date
     and t1.date gt t2.date
     and t1.id = t2.id
     group by t1.id, t1.date;
    quit;
    

    2)

    proc sql;
     select t1.id, t1.date
     from _input t1
     left join _input t2
     on t1.date-4 lt t2.date
     and t1.date gt t2.date
     and t1.id = t2.id
     and t2.value = 0
     group by t1.id, t1.date
     having count(*) ge 2
    ;
    quit;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataset that has two tables in it. I want to do
I have a Dataset that contains tables from a university database, two(actually more) of
I have two big and small dataframes (actually dataset is very very big !).
I have two tables: p_group.full_data, which is a large dataset I'm working on (100k
For each species, I have many datasets. For each dataset, I have many phenotypes.
I have DataSet which has 3 columns. Name - insurance comp. name - treatmentDate
I have a dataset something like this: col_a col_b col_c 1 abc_boy 1 2
I have a dataset that I have modified into an xml document and then
I have a DataSet which I get a DataTable from that I am being
I have a DataSet that contains a few columns. One of these columns is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.