You can use the retain statement to accumulate a variable or a sum statement. This topic is discussed in the SAS Programming 2 class in detail. I would recommend you take this course.
Here is an example to your question but only using one of the variables var1 by year.
DATA WORK.temp; Infile datalines delimiter=','; INPUT YearMonth $ var1 var2 Desired_Accu1 Desired_Accu2 ; year=substr(yearmonth,1,4); CARDS; 2019-01,100,500,100,500 2019-02,200,600,300,1100 2019-03,300,700,600,1800 2019-04,400,100,1000,1900 2019-05,500,200,1500,2100 2019-06,600,300,2100,2400 2019-07,700,400,2800,2800 2019-08,800,500,3600,3300 2019-09,100,500,3700,3800 2019-10,200,600,3900,4400 2019-11,300,700,4200,5100 2019-12,400,100,4600,5200 2020-01,500,200,500,200 2020-02,600,300,1100,500 2020-03,700,400,1800,900 2020-04,800,500,2600,1400 2020-05,100,500,2700,1900 2020-06,200,600,2900,2500 2020-07,300,700,3200,3200 2020-08,400,100,3600,3300 2020-09,500,200,4100,3500 2020-10,600,300,4700,3800 2020-11,700,400,5400,4200 2020-12,800,500,6200,4700 2021-01,100,500,100,500 2021-02,50,300,150,800
; RUN;
proc sort data=WORK.temp; by Year; run;
Data work.temp(keep=year var1 ret_var1); set work.temp; by year; if first.year=1 then ret_var1=0; ret_var1+var1; run;
... View more