SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Arraying variables that have character and numeric codes

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

Arraying variables that have character and numeric codes

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. 

 

 


Accepted Solutions
Solution
‎05-10-2017 11:17 PM
Super User
Posts: 17,823

Re: Arraying variables that have character and numeric codes

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


All Replies
PROC Star
Posts: 169

Re: Arraying variables that have character and numeric codes

[ Edited ]

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

Solution
‎05-10-2017 11:17 PM
Super User
Posts: 17,823

Re: Arraying variables that have character and numeric codes

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.

Contributor
Posts: 50

Re: Arraying variables that have character and numeric codes

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

 

Thanks 

Super User
Posts: 5,082

Re: Arraying variables that have character and numeric codes

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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