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

Hey guys, 

 

Im trying to array some codes that I have that I need to later merge on. The codes are numeric and sometimes use characters to form the code as well (e.g., 111222, 111A11, 222333, 22B044, 22-B11). 

 

The code I'm using is this: 

 

 

data all.matches2;
set all.matches1;
array vars{30} match1-match30;
obs = _n_;
do i = 1 to 30;
match = vars{i};
if not missing(match) then output all.matches2;
end;
drop i match1-match30;
run;

 

 

However, I get this error message: 

 

 

76 data all.matches2;
77 set all.matches1;
78 array vars{30} match1-match30;
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
79 obs = _n_;
80 do i = 1 to 30;
81 match = vars{i};
82 if not missing(match) then output all.matches2;
83 end;
84 drop i match1-match30;
85 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set ALL.MATCHES2 may be incomplete. When this step was stopped there were
0 observations and 11 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds

 

 

 

 

What can I do in order to make my code work? 

 

Thanks for your help. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

They do need to be all the same type as well. If they aren't then you'll need to use multiple arrays OR convert them to the same type.

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Add a $ to your array statement:

 

array vars{30} $30 match1-match30;

 

edited: Sorry ignore mine, Reeza is right, i didn;t look at your program properly

Reeza
Super User

They do need to be all the same type as well. If they aren't then you'll need to use multiple arrays OR convert them to the same type.

r4321
Pyrite | Level 9

How can I convert them to the same type? I suppose I want them to all be character variables (even if they = 222111). 

 

Thanks 

Astounding
PROC Star

Here's a handy syntax that will let you create two arrays (one for numeric variables, and one for character).  This way, you don't need to know which variables are which type:

 

array nums {*} match1-numeric-match30;

array chars {*} match1-character-match30;

 

Then later:

 

do i=1 to dim(nums);    or    do i=1 to dim(chars);

 

However, you still need to figure out what to do from that point.  You can't have a single variable named MATCH that is sometimes numeric and sometimes character.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 5508 views
  • 4 likes
  • 4 in conversation