BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zhangda
Fluorite | Level 6

 

 

Hello,

 

My dataset has three columns, one is apps, the second is approvals, and the third is wantdate, I want to calculate the total apps and total approvals, and then group by wantdate. But I want the date as an accumulating time period. for example,  if the startdate=01/01/2016, and enddate=02/27/2016. The wandate should cover the data as wantdate1, which is 01/01/2016, wantdate2, which is betweem 01/01/2016 and 01/02/2016, wantdate3, which is between 01/01/2016 and 01/03/2016,wantdate4, which is between 01/01/2016 and 01/04/2016.....and the last one is wantdate57, which is   between 01/01/2016 and 02/27/2016. Thanks a lot!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

I think you are looking for something like this:

 

%let startDate=01jan2016;
%let enddate=27feb2016;

data periods;
startdate = "&startdate."d;
do enddate = startdate to "&enddate."d;
    period + 1;
    output;
    end;
format startdate enddate yymmdd10.;
run;

proc sql;
create table want as
select b.period, sum(a.apps) as sumApps, sum(a.approval) as sumApprovals 
from have as a inner join 
    periods as b on a.wantdate between b.startdate and b.enddate
group by b.period;
quit;
PG

View solution in original post

3 REPLIES 3
Reeza
Super User

Sample data and sample output.

 

PGStats
Opal | Level 21

I think you are looking for something like this:

 

%let startDate=01jan2016;
%let enddate=27feb2016;

data periods;
startdate = "&startdate."d;
do enddate = startdate to "&enddate."d;
    period + 1;
    output;
    end;
format startdate enddate yymmdd10.;
run;

proc sql;
create table want as
select b.period, sum(a.apps) as sumApps, sum(a.approval) as sumApprovals 
from have as a inner join 
    periods as b on a.wantdate between b.startdate and b.enddate
group by b.period;
quit;
PG
zhangda
Fluorite | Level 6

Thank you very much!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 775 views
  • 0 likes
  • 3 in conversation