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...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.