I wanted to come here with this challenge I'm facing in these days.
Basically for each record, a different format should be used in a put statement, and it is defined in the data in theirselves.
The challenge is not to split the datasteps and gaining the wanted result within the datastep, so avoid obvious %do loops and similar :)
proc format;
value $a 'FRS'='FIRST';
value $b 'SCN'='SECOND';
run;
data a;
length var $3 res $10 fmt $5;
var='FRS'; fmt='$a.'; res=''; output;
var='SCN'; fmt='$b.'; res=''; output;
run;
data b;
set a;
*your code goes here, the result should go into res variable;
*and should be the "putted" value of var using fmt as format.;
*an obviously non working version can be found here below;
res=put(var,fmt);
run;
Here below what it looks like, res is the expected result:
VAR FMT RES
---------------
"FRS" $a. =put("FRS",$a.)="FIRST"
"SCN" $b. =put("SCN",$b.)="SECOND"