BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RedMcCallen
Calcite | Level 5

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."

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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).

 

PG

View solution in original post

8 REPLIES 8
PGStats
Opal | Level 21

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);
PG
RedMcCallen
Calcite | Level 5
I can't get the formatting to come out right. All I get is this tiny box to put anything into regardless of browser that I use.

However, the above code does not work, keep saying that I have an undeclared array referenced: topMetros.
PGStats
Opal | Level 21

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).

 

PG
RedMcCallen
Calcite | Level 5
Nope, now get the following error message.

NOTE: Line generated by the macro variable "TOPMETROS".
38 array[10] $5. metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460')
___
22
200
ERROR: Undeclared array referenced: array.
NOTE: Line generated by the macro variable "TOPMETROS".
38 array[10] $5. metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460')
_______
68
ERROR 22-322: Syntax error, expecting one of the following: +, =.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 68-185: The function METRO10 is unknown, or cannot be accessed.
PGStats
Opal | Level 21

The code as posted is tested and it works. What did you try?

PG
RedMcCallen
Calcite | Level 5
22 GOPTIONS ACCESSIBLE;
23 %let topMetros = array[10] $5 metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940'
23 ! '14460');
24
25 %macro count(toomany);
26 %do i = 1 %to &toomany;
27 data geog.uscis_ois_lpr_s5_mtr&i. (drop = metro:);
28 set geog.uscis_ois_lpr_s5_metros;
29 &topMetros;
30
31 if CBSA_CODE = topMetros[&i.] then
32 output geog.uscis_ois_lpr_s5_mtr&i.;
33
34 run;
35
36 %end;
37 %mend count;
38 %count(10);
ERROR: Undeclared array referenced: array.
NOTE 138-205: Line generated by the macro variable "TOPMETROS".
38 array[10] $5 metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460')
_
22
ERROR 22-322: Syntax error, expecting one of the following: +, =.

NOTE: Line generated by the macro variable "TOPMETROS".
38 array[10] $5 metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460')
_
200
ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: Line generated by the macro variable "TOPMETROS".
38 array[10] $5 metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460')
_______
68
ERROR 68-185: The function METRO10 is unknown, or cannot be accessed.
2 The SAS System 15:19 Monday, November 14, 2016


NOTE: Line generated by the macro variable "TOPMETROS".
38 array[10] $5 metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460')
_______
388
ERROR 388-185: Expecting an arithmetic operator.

NOTE: Line generated by the macro variable "TOPMETROS".
38 array[10] $5 metro1-metro10 ('35620' '31090' '33100' '16980' '41860' '47900' '26420' '19100' '41940' '14460')
_______
76
ERROR 76-322: Syntax error, statement will be ignored.

ERROR: Undeclared array referenced: topMetros.
ERROR: Variable topMetros has not been declared as an array.

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
3537:113
WARNING: The variable 'metro:'n in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set GEOG.USCIS_OIS_LPR_S5_MTR1 may be incomplete. When this step was stopped there were 0 observations and 36
variables.
WARNING: Data set GEOG.USCIS_OIS_LPR_S5_MTR1 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
PGStats
Opal | Level 21

It is

 

%let topMetros = array topMetros[10] $5 metro1-metro10...

PG
RedMcCallen
Calcite | Level 5
Can't believe I missed that! I was focusing on the main bloc. But still, I am an editor and should have caught that.

Thanks.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 6438 views
  • 0 likes
  • 2 in conversation