使用do循环在SAS中创建新变量

时间:2015-09-25 20:34:47

标签: sas sas-macro do-loops

我有一个SAS程序,具有基准年数据和五年预测年。所有预测年份都有相同的计算,但只需使用上一年的数据作为计算的基准年。我想避免复制数据5次,只是更改我的变量名称的后缀。只有一个预测年并且有一个do循环或数组来改变变量名的后缀会很棒。以下是根据您的输入更新的代码:

*Start macro loop - takes two parameters, the first year of the dataset to be created and the last year;
%macro loop(year_start, year_end);

  *loop over years;

  %do year=&year_start %to &year_end;
  *create macro variable for previous years;
  %let prev_year=%eval(&year_start-1);

DATA SchoolAidFY&year_start.;
Set work.forecastinputs;

* COST PER PUPIL AMOUNTS;                       
L201_FY&start_year.=    L203_FY&prev_year.;                             
L202_FY&start_year.=        Round(SCPP*SPG_FY&start_year.,1);           
L203_FY&start_year.=        Sum(L201_FY&start_year.,L202_FY&start_year.);                   
L204_FY&start_year.=    L206_FY&prev_year.;                     
L205_FY&start_year.=        Round(TS_SCPP*SPG_FY&start_year.,0.01);     
L206_FY&start_year.=        Sum(L204_FY&start_year.,L205_FY&start_year.);               
L207_FY&start_year.=    L209_FY&prev_year.;                     
L208_FY&start_year.=        Round(PD_SCPP*SPG_FY&start_year.,0.01);     
L209_FY&start_year.=        Sum(L207_FY&start_year.,L208_FY&start_year.);           
L210_FY&start_year.=    L212_FY&prev_year.;                     
L211_FY&start_year.=        Round(EI_SCPP*SPG_FY&start_year.,0.01);     
L212_FY&start_year.=        Sum(L210_FY&start_year.,L211_FY&start_year.);               
L213_FY&start_year.=    L215_FY&prev_year.;                     
L214_FY&start_year.=        Round(TL_SCPP*SPG_FY&start_year.,0.01);     
L215_FY&start_year.=        Sum(L213_FY&start_year.,L214_FY&start_year.);                   

 Run;


  %end;
  *end of do loop;

  %mend;
  *end of macro;   

 %loop(year_start=17, year_end=20);

这是日志:

2                                                          The SAS System                           11:35 Monday, September 28, 2015

58         L215_FY&start_year.=     Sum(L213_FY&start_year.,L214_FY&start_year.);                   
59         
60          Run;
61         
62         
63           %end;
64           *end of do loop;
65         
66           %mend;
67           *end of macro;
68         
69          %loop(year_start=17, year_end=20);
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent symbolic reference START_YEAR not resolved.
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
                                       _______
                                       180
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
69       ! L207_FY&start_year.= L209_FY&prev_year.;
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
                                                                                      _______
                                                                                      180
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
69       ! L207_FY&start_year.= L209_FY&prev_year.;
ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
                                                     _______
                                                     180
69       ! L207_FY&start_year.= L209_FY&prev_year.;
ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
69       ! L207_FY&start_year.= L209_FY&prev_year.;
           _______
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.

3                                                          The SAS System                           11:35 Monday, September 28, 2015

WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69                L208_FY&start_year.=  Round(PD_SCPP*SPG_FY&start_year.,0.01);   L209_FY&start_year.=
                  _______                                                         _______
_______                                                                                                                             
                  180                                                             180
180                                                                                  
69       ! Sum(L207_FY&start_year.,L208_FY&start_year.);    L210_FY&start_year.= L212_FY&prev_year.;       L211_FY&start_year.=
69       ! Round(EI_SCPP*SPG_FY&start_year.,0.01);
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69                L208_FY&start_year.=  Round(PD_SCPP*SPG_FY&start_year.,0.01);   L209_FY&start_year.=
69       ! Sum(L207_FY&start_year.,L208_FY&start_year.);    L210_FY&start_year.= L212_FY&prev_year.;       L211_FY&start_year.=
                                                                                                           _______
                                                                                                           180
69       ! Round(EI_SCPP*SPG_FY&start_year.,0.01);
ERROR 180-322: Statement is not valid or it is used out of proper order.

WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69            L212_FY&start_year.=  Sum(L210_FY&start_year.,L211_FY&start_year.);     L213_FY&start_year.= L215_FY&prev_year.;
              _______                                                                 _______
              180                                                                     180
69       !  L214_FY&start_year.=  Round(TL_SCPP*SPG_FY&start_year.,0.01);   L215_FY&start_year.=
69       ! Sum(L213_FY&start_year.,L214_FY&start_year.);
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69            L212_FY&start_year.=  Sum(L210_FY&start_year.,L211_FY&start_year.);     L213_FY&start_year.= L215_FY&prev_year.;
69       !  L214_FY&start_year.=  Round(TL_SCPP*SPG_FY&start_year.,0.01);   L215_FY&start_year.=
            _______
            180
69       ! Sum(L213_FY&start_year.,L214_FY&start_year.);
ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "LOOP".
69            L212_FY&start_year.=  Sum(L210_FY&start_year.,L211_FY&start_year.);     L213_FY&start_year.= L215_FY&prev_year.;
69       !  L214_FY&start_year.=  Round(TL_SCPP*SPG_FY&start_year.,0.01);   L215_FY&start_year.=
                                                                            _______
                                                                            180
69       ! Sum(L213_FY&start_year.,L214_FY&start_year.);
ERROR 180-322: Statement is not valid or it is used out of proper order.

WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
4                                                          The SAS System                           11:35 Monday, September 28, 2015

WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.SCHOOLAIDFY17 may be incomplete.  When this step was stopped there were 0 observations and 1197 
         variables.
WARNING: Data set WORK.SCHOOLAIDFY17 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent symbolic reference START_YEAR not resolved.
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
                                       _______
                                       180
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
69       ! L207_FY&start_year.= L209_FY&prev_year.;
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
                                                                                      _______
                                                                                      180
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
69       ! L207_FY&start_year.= L209_FY&prev_year.;
ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
                                                     _______
                                                     180
69       ! L207_FY&start_year.= L209_FY&prev_year.;
ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
69       ! L207_FY&start_year.= L209_FY&prev_year.;
           _______
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
5                                                          The SAS System                           11:35 Monday, September 28, 2015


WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69                L208_FY&start_year.=  Round(PD_SCPP*SPG_FY&start_year.,0.01);   L209_FY&start_year.=
                  _______                                                         _______
_______                                                                                                                             
                  180                                                             180
180                                                                                  
69       ! Sum(L207_FY&start_year.,L208_FY&start_year.);    L210_FY&start_year.= L212_FY&prev_year.;       L211_FY&start_year.=
69       ! Round(EI_SCPP*SPG_FY&start_year.,0.01);
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69                L208_FY&start_year.=  Round(PD_SCPP*SPG_FY&start_year.,0.01);   L209_FY&start_year.=
69       ! Sum(L207_FY&start_year.,L208_FY&start_year.);    L210_FY&start_year.= L212_FY&prev_year.;       L211_FY&start_year.=
                                                                                                           _______
                                                                                                           180
69       ! Round(EI_SCPP*SPG_FY&start_year.,0.01);
ERROR 180-322: Statement is not valid or it is used out of proper order.

WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69            L212_FY&start_year.=  Sum(L210_FY&start_year.,L211_FY&start_year.);     L213_FY&start_year.= L215_FY&prev_year.;
              _______                                                                 _______
              180                                                                     180
69       !  L214_FY&start_year.=  Round(TL_SCPP*SPG_FY&start_year.,0.01);   L215_FY&start_year.=
69       ! Sum(L213_FY&start_year.,L214_FY&start_year.);
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69            L212_FY&start_year.=  Sum(L210_FY&start_year.,L211_FY&start_year.);     L213_FY&start_year.= L215_FY&prev_year.;
69       !  L214_FY&start_year.=  Round(TL_SCPP*SPG_FY&start_year.,0.01);   L215_FY&start_year.=
            _______
            180
69       ! Sum(L213_FY&start_year.,L214_FY&start_year.);
ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "LOOP".
69            L212_FY&start_year.=  Sum(L210_FY&start_year.,L211_FY&start_year.);     L213_FY&start_year.= L215_FY&prev_year.;
69       !  L214_FY&start_year.=  Round(TL_SCPP*SPG_FY&start_year.,0.01);   L215_FY&start_year.=
                                                                            _______
                                                                            180
69       ! Sum(L213_FY&start_year.,L214_FY&start_year.);
ERROR 180-322: Statement is not valid or it is used out of proper order.

WARNING: Apparent symbolic reference START_YEAR not resolved.
6                                                          The SAS System                           11:35 Monday, September 28, 2015

WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.SCHOOLAIDFY17 may be incomplete.  When this step was stopped there were 0 observations and 1197 
         variables.
WARNING: Data set WORK.SCHOOLAIDFY17 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent symbolic reference START_YEAR not resolved.
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
                                       _______
                                       180
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
69       ! L207_FY&start_year.= L209_FY&prev_year.;
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
                                                                                      _______
                                                                                      180
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
69       ! L207_FY&start_year.= L209_FY&prev_year.;
ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
                                                     _______
                                                     180
69       ! L207_FY&start_year.= L209_FY&prev_year.;
ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
69       ! L207_FY&start_year.= L209_FY&prev_year.;
           _______
           180

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.SCHOOLAIDFY17 may be incomplete.  When this step was stopped there were 0 observations and 1197 
         variables.
WARNING: Data set WORK.SCHOOLAIDFY17 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent symbolic reference START_YEAR not resolved.
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
                                       _______
                                       180
69       ! Round(TS_SCPP*SPG_FY&start_year.,0.01);   L206_FY&start_year.=  Sum(L204_FY&start_year.,L205_FY&start_year.);
69       ! L207_FY&start_year.= L209_FY&prev_year.;
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
WARNING: Apparent symbolic reference START_YEAR not resolved.
NOTE: Line generated by the invoked macro "LOOP".
69         ,L202_FY&start_year.);      L204_FY&start_year.= L206_FY&prev_year.;       L205_FY&start_year.=
                                                                                      _______


NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.SCHOOLAIDFY17 may be incomplete.  When this step was stopped there were 0 observations and 1197 
         variables.
WARNING: Data set WORK.SCHOOLAIDFY17 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

70         
71         
72         
73         
74         GOPTIONS NOACCESSIBLE;
75         %LET _CLIENTTASKLABEL=;
76         %LET _CLIENTPROJECTPATH=;
77         %LET _CLIENTPROJECTNAME=;
78         %LET _SASPROGRAMFILE=;
79         
80         ;*';*";*/;quit;run;
81         ODS _ALL_ CLOSE;
82         
83         
84         QUIT; RUN;
85         

1 个答案:

答案 0 :(得分:0)

如果您需要不同的数据集,则需要一个宏循环。如果您想要一个数据集

*Start macro loop - takes two parameters, the first year of the dataset to be created and the last year;
options mprint symbolgen;
%macro loop(year_start, year_end);
  *loop over years;
  %do year=&year_start %to &year_end;

  *create macro variable for previous years;
  %let prev_year=%eval(&year_start-1);

  DATA SchoolAid_FY&year_start.;
   Set work.SchoolAid_FY&prev_year.; 

  * COST PER PUPIL AMOUNTS;                       
  L201_FY&start_year.=  L203_FY&prev_year.;                                  
  L202_FY&start_year.=  Round(SCPP*SPG_FY&prev_year.,1);         
  L203_FY&start_year.= Sum(L201_FY&prev_year.,L202_FY&prev_year.); 

  *Rest of your code;

  Run;
  %end;
  *end of do loop;

  %mend;
  *end of macro;   

然后你必须调用宏,例如,如果你想从15到20使用year_start = 15和year_end = 20。

%loop(year_start=15, year_end=20);