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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 1780 views
  • 3 likes
  • 2 in conversation