Hi,
Can anyone help me with the below error.
data _null_;
set macro_name(firstobs=1 obs=10);
n+1;
call execute('proc reg data=macro_var outest=out EDF; model dPD='||name||'/noprint; run;
Data _null_;call symput(''NN'','||trim(left(n))||');run;
Data _null_;set out(keep=_RSQ_ '||trim(left(name))||');
call symput(''RSQ'''||&NN||',_RSQ_);
WARNING: Apparent symbolic reference NN not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
a numeric constant, a datetime constant, a missing value, INPUT, PUT.
run;'
);
run;
I am trying to create 10 macro variables RSQ1,...,RSQ10 with assigned values from table out, sequentially. The error comes when concatenating RSQ with NN which is assigned 1,...,10.
If anyone can help on this error that would be great.
John
So, there are few issues with the code...but here is something that works
data _null_;
set sashelp.class;
if name = "Philip" then call symput("%sysfunc(cat(RSQ,23))",age);
run;
%put &rsq23.;
So, I think you need to modify your code...something like this (see in red):
data _null_;
set macro_name(firstobs=1 obs=10);
n+1;
call execute('proc reg data=macro_var outest=out EDF; model dPD='||name||'/noprint; run;
Data _null_;
call symput("NN",trim(left(n)));
run;
Data _null_;
set out(keep=_RSQ_ name);
call symput("%sysfunc(cat(RSQ,&NN.))",_rsq_);
It looks like you're overcomplicating things a bit. Why not remove the first DATA step within CALL EXECUTE? Then the second one could use:
call symputx(''RSQ''' || left(_n_)', _rsq_);
When you switch from SYMPUT to SYMPUTX, the TRIMming is performed automatically. And it looks like you could switch to _n_ and not have to bother creating n.
Good luck.
You should look for a way to make your code simpler. How about doing all the regressions in one call to PROC REG.
Hi,
thanks for the responses. I used a combination of the suggestions, which is below.
data _null_;
set macro_name(firstobs=1 obs=10);
n+1;
call execute('proc reg data=macro_var outest=out EDF; model dPD='||name||'/noprint; run;
Data _null_;set out(keep=_RSQ_ '||trim(left(name))||');
call symput(%sysfunc(cat(RSQ,'||_N_||')),_RSQ_);
run;'
);
run;
but I am still getting an errors. The macro variables RSQ1,..,RSQ10 are not being created even though the concatenation is working.
output is below.
1 +
Data _null_;set out(keep=_RSQ_ dAAvg_weekly_hrs1); call symput(RSQ1,_RSQ_);
run;
ERROR: Symbolic variable name . must begin with a letter or underscore.
_RSQ_=0.105132549 RSQ1=. _ERROR_=1 _N_=1
Any suggestions would be great.
John
John,
I'll stick by my original response, simplify this and get rid of the pieces that you don't need. Perhaps the rest will become clearer. To give you another example of what I mean, the DATA _NULL_ step brings in the variable NAME, but doesn't use it. So simplify that line in the program, resulting in:
Data _null_; set out (keep=_RSQ_);
That won't fix the problem you are encountering, but it might make the program easier to understand. Looking a little more carefully at the next line, this fix comes to mind:
call symputx("RSQ" || left(_N_), _RSQ_);
Good luck. It should be that simple.
John,
Consider either Astounding's solution or Data _null_'s if you can consolidate to one proc.
You are having issues with embedding macro references within call execute. It can be done but is tricky.
In the first example you posted, the macro compiler will try to replace &NN during the data _NULL_ step compliation and causes and error with compiling.
In your second example, %sysfunc is a macro call which call data step functions to return a value. Again the macro function is called at compile time and can not find a value for _n_. .
Astounding suggestion fixes that.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.