-
Erreur codes macro SAS
Bonjour,
j'ai la macro suivante d'un document, mais elle ne marche pas bien, j'aimerais bien savoir comment je peux corriger l'erreur, merci!
Les codes sont:
%macro partition(data = , target = , smpratio = ,
seed = , train = , validate = );
/**************************************************************
* MACRO: partition()
* GOAL: divide to training and validation sets that
* represent original target variable's proportion
* PARAMETERS: data = raw dataset
* target = target variable
* smprate = ratio between training and validation
* set * seed = random seed for sampling
**************************************************************/
ods select none;
ods output variables = _varlist;
proc contents data = &data;
run;
proc sql;
select variable into: num_var separated by ' '
from _varlist
where lowcase(type) = 'num';
quit;
proc sort data = &data out = _tmp1;
by ⌖
run;
proc surveyselect data = _tmp1 samprate = &smpratio
out = _tmp2 seed = &seed outall;
strata &target / alloc = prop;
run;
data &train &validate;
set _tmp2; keep &num_var ⌖
if selected = 0 then output &train;
else output &validate;
run;
proc datasets nolist;
delete _:;
quit;
ods select all;
%mend;
%partition(data = sashelp.iris, target = species, smpratio = 0.5,
seed = 20110901, train = iris_train, validate = iris_validate);
La log:
109 %macro partition(data = , target = , smpratio = ,
110 seed = , train = , validate = );
111 /**************************************************************
112
113 * MACRO: partition()
114 * GOAL: divide to training and validation sets that
115 * represent original target variable's proportion
116 * PARAMETERS: data = raw dataset
117 * target = target variable
118 * smprate = ratio between training and validation
119 * set * seed = random seed for sampling
120 **************************************************************/
121 ods select none;
122 ods output variables = _varlist;
123 proc contents data = &data;
124 run;
125 proc sql;
126 select variable into: num_var separated by ' '
127 from _varlist
128 where lowcase(type) = 'num';
129 quit;
130 proc sort data = &data out = _tmp1;
131 by ⌖
132 run;
133 proc surveyselect data = _tmp1 samprate = &smpratio
134 out = _tmp2 seed = &seed outall;
135 strata &target / alloc = prop;
136 run;
137 data &train &validate;
138 set _tmp2; keep &num_var ⌖
139 if selected = 0 then output &train;
140 else output &validate;
141 run;
142 proc datasets nolist;
143 delete _:;
144 quit;
145 ods select all;
146 %mend;
147 %partition(data = sashelp.iris, target = species, smpratio = 0.5,
148 seed = 20110901, train = iris_train, validate = iris_validate);
NOTE: PROCEDURE CONTENTS used (Total process time):
real time 0.10 secondes
cpu time 0.01 secondes
NOTE: The data set WORK._VARLIST has 5 observations and 7 variables.
NOTE: No rows were selected.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.07 secondes
cpu time 0.01 secondes
NOTE: Input data set is already sorted; it has been copied to the output data set.
NOTE: There were 150 observations read from the data set SASHELP.IRIS.
NOTE: The data set WORK._TMP1 has 150 observations and 5 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.00 secondes
cpu time 0.00 secondes
NOTE: The data set WORK._TMP2 has 150 observations and 12 variables.
NOTE: PROCEDURE SURVEYSELECT used (Total process time):
real time 0.08 secondes
cpu time 0.01 secondes
WARNING: Apparent symbolic reference NUM_VAR not resolved.
22 : impossible de déterminer LINE et COLUMN.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has
occurred.
ERROR 22-322: Syntax error, expecting one of the following: un nom, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
200 : impossible de déterminer LINE et COLUMN.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has
occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: La variable num_var dans la liste DROP, KEEP, ou RENAME n'a jamais été référencée.
WARNING: La variable num_var dans la liste DROP, KEEP, ou RENAME n'a jamais été référencée.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.IRIS_TRAIN may be incomplete. When this step was stopped there were 0 observations and 1
variables.
WARNING: Table WORK.IRIS_TRAIN non remplacée car cette étape a été interrompue.
WARNING: The data set WORK.IRIS_VALIDATE may be incomplete. When this step was stopped there were 0 observations and 1
variables.
WARNING: Table WORK.IRIS_VALIDATE non remplacée car cette étape a été interrompue.
NOTE: DATA statement used (Total process time):
real time 0.02 secondes
cpu time 0.01 secondes
NOTE: Deleting WORK._TMP1 (memtype=DATA).
NOTE: Deleting WORK._TMP2 (memtype=DATA).
NOTE: Deleting WORK._VARLIST (memtype=DATA).
NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.00 secondes
cpu time 0.00 secondes