Replacing link statements

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Replacing link statements

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.


Accepted Solutions
Solution
‎12-03-2014 02:43 PM
Super User
Posts: 5,085

Re: Replacing link statements

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.

View solution in original post


All Replies
Super User
Posts: 5,085

Re: Replacing link 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?

Occasional Contributor
Posts: 14

Re: Replacing link statements

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.

Occasional Contributor
Posts: 14

Re: Replacing link statements

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 ;

Solution
‎12-03-2014 02:43 PM
Super User
Posts: 5,085

Re: Replacing link statements

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.

Occasional Contributor
Posts: 14

Re: Replacing link statements

That helped! Thank you!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 201 views
  • 0 likes
  • 2 in conversation