To get the values, you will need to take a couple steps to get them to correctly output. And these steps are more 'hacks' than obvious.
So, when you utilize CONCAT, it will output a string no matter what. Which is why your line SET @test_data = Concat(@mls_number_0,@i)
always returns the name of the variable as that is what comes from the CONCAT function. A string of the name.
Well good news is that is a good portion of the first step. Now before I go into the first step I am going to give a quick overview of what needs to be done so that when I explain the first step it does not seem like a complete nut is trying to talk to you about how to do this.
Steps to get value:
- Write out a string version of the name of the variable
- Around that string, further create that string to contain necessary AMPscript functions and code blocks that would correctly set the value (usually requires CONCAT)
- Utilize TreatAsContent() to render your AMPscript string and process it to correctly assign the value.
Here is an example step by step:
STEP 1:
SET @varName = CONCAT('@mls_number_0',@i)
STEP 2:
SET @ampStr = CONCAT('%','%=v(',@varName,')=%','%')
STEP 3:
SET @test_data = TreatAsContent(@ampStr)
Then you can output the @test_data
like you had previously.
There are different ways you can do this, like you can set the AMPscript string to set @test_data
inside of it and merge 2 and 3, or other things depending on needs, etc. But this way is usually the easiest to explain and to read, which is why I tend to push it out there in these cases.
Here is an example of it all combined into a single script:
%%[
SET @var1 = "A"
SET @var2 = "B"
SET @var3 = "C"
FOR @i=1 TO 3 DO
SET @test_data = TreatAsContent(Concat('%','%=v(@var', @i,')=%','%'))
]%%
<p>%%=v(@test_data)=%%</p>
%%[ NEXT @i ]%%