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!!!
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
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;
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.
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.