What does this piece of code do?
RETURNED_VALUE = PUT(LOOKUP,$MATRIX.);
If the actual value of LOOKUP is "0101" then it writes the formatted value using the format, in this case "001" into the variable Returned_value. By default Returned_value would be a character variable. If not previously defined or had a length assigned it would have length as assigned the first time that line of code executes.
What values do you have for "form" in your original data?
There are reasons we recommend providing some example data, preferably as a data step so can create a set to work with. And also provide what you expect for output.
You have do loop that would result in only the value of Returned_value remaining in the data set of the last "item" examined.
It appears you are attempting to use someone else's code. I might suggest instead of building a format that you use to make a string value that is then used with an input to get the numeric value that you create an informat to create the numeric value from. A brief example with an intentional call to a value not provided which generates an error and diagnostics:
proc format library=work;
invalue matrix
'0101' = 1
'0102' = 2
'0103' = 3
other=_error_;
run;
data example;
input form $;
do i= 1 to 4;
slot = input( cats(form,put(i,z2.) ),matrix. );
output;
end;
datalines;
01
;
run;
You may have other issues related to the sizes of your arrays. The macro variable &items resolves to 40 and &Matrix_slots=104.
So the largest number of matrix variables that would be assigned values in this case is likely 40 on any row of data.
Did you get this code to work without any macro variables? With a data set data2 with only a few records and few variables to verify that the logic worked for a known case?
And if the whole purpose of this is to find which element of an array has a specific value then there are two functions, depending on whether the value is numeric or character that will do that:
slot = Whichc ('0101', of item(*) ); would return the first position of '0101' in the array item.
Without a little more concrete as to what is actually in your data set, variable values and types and actual desired result I'm not sure what else I might be able to provide in the way of assistance.
... View more