BookmarkSubscribeRSS Feed
mikki
Calcite | Level 5

Hi All,

    I created a macro that create global variables based based on the program name I pass. when I execute macro it is not stop running. When I manually stop I am getting following error.   What is wrong with my code?

The input dataset has the value "l_demo_fas".

Please help!!!

129   %datapgm(pgm=l_demo_fas);

ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition.

ERROR: The %TO value of the %DO I loop is invalid.

ERROR: The macro DATAPGM will stop executing.

*****Here is my code****

%macro datapgm(pgm=);

%global nbt nbf outname pgmpath;

data _NULL_;

  set adam.toc_prog;

  where pgm_id = "&pgm";

  call symput('nbt',compress(input(strip(put(numtitle,3.)),$3.)));

  call symput('nbf',compress(input(strip(put(numfoot,3.)),$3.)));

  call symput('outname', compress(strip(outname)));

  call symput('pgmpath',compress(strip(pgmpath)));

 

%do i = 1 %to &nbt;

    %global t&i;

     call symput('t'||"&i",strip(title_&i));

%end;

%do j = 1 %to &nbf;

    %global f&j;

    call symput('f'||"&j",strip(foot_&j));

%end;

run;

%mend;

 

%datapgm(pgm=l_demo_fas);

%put &nbt.  &nbf;

%put &t1  &t2 &t3;

%put &f1;

%put &outname;

%put &pgmpath;

Thanks in advance!!!

2 REPLIES 2
jakarman
Barite | Level 11

1/ as your are trying to symput nbt nbf in the datastep the macro will not be able to get those values. There will be a timing problem on valuses

2/ Debug your macro wih optionc mprint mlogic symbolgen etc...o

---->-- ja karman --<-----
mikki
Calcite | Level 5

Hi Jaap,

   If I run part by part working fine.. kind of weird.

  As you have mentioned it looks like timing issue.

Now I used 2 data steps in the macro. so far working fine and I used %eval for do loop. see the following corrected program.

Thanks for you suggestion..

%macro datapgm(pgm=);

data ttft;

  set adam.toc_prog;

where pgm_id = "&pgm";

%global nbt nbf outname pgmpath;

 

  call symput('nbt', compress(input(strip(put(numtitle,3.)),$3.)));

  call symput('nbf', compress(input(strip(put(numfoot,3.)),$3.)));

  call symput('outname', compress(strip(outname)));

  call symput('pgmpath',compress(strip(pgmpath)));

run;

data _NULL_;

   set ttft;

   %do i = 1 %to %eval(&nbt);

     %global t&i;

     call symput('t'||"&i",strip(title_&i));

   %end;

   %do j = 1 %to %eval(&nbf);

      %global f&j;

      call symput('f'||"&j", strip(foot_&j));

   %end;

run;

%mend;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2430 views
  • 3 likes
  • 2 in conversation