Hi all
I am trying to replace LINK statements from an old code. The code appears like this:
data test1;
set test;
array tes{15} test0 - test14;
do i=1 to 15;
test_g = i - 1;
link testlbl;
score=exp(pd);
tes{i} = f_score;
end;
return;
testlbl:
%test_macro;
run;
I tried to replace it with this code:
data test1;
set test;
array tes{15} test0 - test14;
do i=1 to 15;
test_g = i - 1;
%test_macro;
score=exp(pd);
tes{i} = f_score;
end;
return;
run;
The latter code with direct macro substitution in place of link seems to give different results. I am not sure what I am missing. I tried goto statement as well. That also seems to give incorrect results.
How the link can be substituted? Thanks in advance.
In this particular case, you could remove all the linking, and just place this much in the middle of your DO loop:
if depth ne . then depth1 = 10;
calc1_check = 1;
test = 1;
if station='site_1'
then elevatn=6650-depth;
else if station='site_2'
then elevatn=5500-depth;
Based on what you posted, macro language is not even needed. However, it's not clear that the macro is really this simple. Perhaps it actually has some additional features that you removed for purposes of simplicity when posting in this forum. The programmer may have intended that some of the code within the macro gets executed every time and some doesn't. At any rate, it should be easy enough to replicate the original intention using IF/THEN statements.
The simplest answer would be that the definition of %TEST_MACRO contains a RETURN statement ... possibly even several RETURN statements controlled by IF/THEN statements. If that's the case, the macro would have to be rewritten. RETURN at the bottom of the DATA step would return to the LINK statement. RETURN without a LINK statement would return to the top of the DATA step code.
Why is it that you need to remove the LINK?
I am trying to create a thread to run the above code using PROC DS2. LINK statement doesn't seem to work inside that procedure.
The macro did have return statements. I removed them as well. The macro looks something like this:
%macro test_macro;
calc1:
if depth ne . then depth1 = 10;
calc1_check = 1;
link calc2;
test = 1;
return;
calc2:
if station='site_1'
then elevatn=6650-depth;
else if station='site_2'
then elevatn=5500-depth;
return;
%mend ;
In this particular case, you could remove all the linking, and just place this much in the middle of your DO loop:
if depth ne . then depth1 = 10;
calc1_check = 1;
test = 1;
if station='site_1'
then elevatn=6650-depth;
else if station='site_2'
then elevatn=5500-depth;
Based on what you posted, macro language is not even needed. However, it's not clear that the macro is really this simple. Perhaps it actually has some additional features that you removed for purposes of simplicity when posting in this forum. The programmer may have intended that some of the code within the macro gets executed every time and some doesn't. At any rate, it should be easy enough to replicate the original intention using IF/THEN statements.
That helped! Thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.