07-18-2014 06:00 PM
I have another question about how to pass values from macros to variables in data step. I tried both 'call execute' and 'dosubl' as instructed by the replies in my other post for passing variable values into macros. I got error messages for both statements.
The following is a simple sample code just for describing my question. I want to create a new variable according to the values of 'times' in data 'test_data'. Thanks a lot for your input.
%if (&finish > 4) %then new = 'great than 4';
rc = dosubl'%test('||times||')');
07-18-2014 07:19 PM
What is it that you actually want to do? The macro that you wrote is one that will just generate most of an assignment statement that could be used in a data step. Note that it is missing the semi-colon that would mark the end of the assignment statement as the semi-colon that is there is the one that ends the %IF %THEN statement.
If you just want to mimic the behavior of a FORMAT then just have the macro generate the string that you want and then use %RESOLVE() to call it and return the string that it generates.
%if (&finish > 4) %then great than 4 ;
test = resolve(cats('%test(',times,')'));
put times= test=;
07-19-2014 08:55 AM
Now if you want to test if you can have a macro that does actual data and proc calls then here is a better example.
In this case the macro stores the result into a global macro variable that the data step can then retrieve with SYMGET() function.
length new $200;
if (&finish = 4) then new='equal to 4';
else if (&finish > 4) then new='greater than 4';
else new='less than 4';
do times=3 to 5;
rc = dosubl(cats('%test(',times,')'));
put (_all_) (=);