All, I am trying to reference a global array so that I can output a series of files based on the matching of values in a variable. Below is the code:
%let topMetros = array[10] $5. metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460');
%macro count(toomany);
%do i = 1 %to &toomany;
data geog.uscis_ois_lpr_s5_mtr&i.;
f CBSA_CODE = topMetros[&i]. then output geog.uscis_ois_lpr_s5_mtr&i.;
%end;
%mend count;
%count(10);
run;
When I do I get an error message of the following:
"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."
OK, a tested version now:
data have;
do CBSA_CODE = '35620', '31090', '33100', '16980', '41860', '47900', '26420', '19100', '41940', '14460';
output;
end;
run;
options mprint;
%let topMetros = array topMetros[10] $5 metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460');
%macro count(toomany);
%do i = 1 %to &toomany;
data uscis_ois_lpr_s5_mtr&i.;
set HAVE;
&topMetros;
if CBSA_CODE = topMetros[&i.] then output;
drop metro:;
run;
%end;
%mend count;
%count(10);
Replaced %topMetros (macro call) with &topMetros (macro variable reference).
Assuming input dataset is called HAVE, I think you mean:
%let topMetros = array topMetros[10] $5 metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460');
%macro count(toomany);
%do i = 1 %to &toomany;
data geog.uscis_ois_lpr_s5_mtr&i.;
set HAVE;
%topMetros;
if CBSA_CODE = topMetros[&i.] then output;
drop metro:;
run;
%end;
%mend count;
%count(10);
OK, a tested version now:
data have;
do CBSA_CODE = '35620', '31090', '33100', '16980', '41860', '47900', '26420', '19100', '41940', '14460';
output;
end;
run;
options mprint;
%let topMetros = array topMetros[10] $5 metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460');
%macro count(toomany);
%do i = 1 %to &toomany;
data uscis_ois_lpr_s5_mtr&i.;
set HAVE;
&topMetros;
if CBSA_CODE = topMetros[&i.] then output;
drop metro:;
run;
%end;
%mend count;
%count(10);
Replaced %topMetros (macro call) with &topMetros (macro variable reference).
The code as posted is tested and it works. What did you try?
It is
%let topMetros = array topMetros[10] $5 metro1-metro10...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.