BookmarkSubscribeRSS Feed
JohnV
Calcite | Level 5


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  

6 REPLIES 6
AncaTilea
Pyrite | Level 9

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_);


Smiley Happy

Astounding
PROC Star

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.

data_null__
Jade | Level 19

You should look for a way to make your code simpler.  How about doing all the regressions in one call to PROC REG.

data class;
   set sashelp.class;
   v1=weight;
   v2=height;
   v3=weight*height;
   v4=ranuni(
123);
   v5=v4+v4;
  
run;
proc reg data=class outest=est;
   model age = V: / selection=rsquare stop=1;
  
run;
proc print;
  
run;
JohnV
Calcite | Level 5


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

Astounding
PROC Star

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.

LarryWorley
Fluorite | Level 6

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-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
  • 6 replies
  • 1362 views
  • 0 likes
  • 5 in conversation