BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasdusern
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

5 REPLIES 5
Astounding
PROC Star

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?

sasdusern
Calcite | Level 5

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.

sasdusern
Calcite | Level 5

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 ;

Astounding
PROC Star

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.

sasdusern
Calcite | Level 5

That helped! Thank you!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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