BookmarkSubscribeRSS Feed
andrew0845
Calcite | Level 5

I am looping symput in a macro with a list of selected variables.

I have no problem run the symput command outside the macro; But when I put it in the macro, it always report error.

%marcro( varlist=,…….)

%let var1   = %qscan(&varlist, i)

………

%do %while(…….);

data _null_; set a1 end=no_more;

call symput( 'MU'||left(_N_), &var1._Mean);

call symput( 'SD'||left(_N_), &var1._stdDev  );

if no_more then call symput('count',_n_);

run;

……………..

%end;

%mend;

Error message like this :

NOTE: Line generated by the macro variable "VAR1".

1      PDT_Vpp_Mean

-----

22

ERROR 22-322: Syntax error, expecting one of the following: !,

!!, &, *, **, +, ',', -, /, <, <=, <>, =, >, ><,

>=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE,

NG, NL, NOTIN, OR, ^=, |, ||, ~=.

253: LINE and COLUMN cannot be determined.

*****************


Please advise me how to solve this problem. Thanks!


Andrew

5 REPLIES 5
data_null__
Jade | Level 19

Why do you want to put so much data into macro variables?  Sounds like a bad idea to me.

Show the data in WORK.A1 you may not need any of the macro bit just better data step.

Quentin
Super User

Agree with _null_ , seems like an odd design.

That said, would expect the cause is a problem of macro processor not %unquoting the value of &var1.

Assuming varlist is just a space-delimited list of variable names, you could change %qscan to %scan.

--Q.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Astounding
PROC Star

Also note that the error is being generated by portions of the code that you did not show us:  the ...... following the DATA step.  Other than that, I agree with the earlier posters.

Good luck.

Ksharp
Super User

Maybe I understand where is the problem .

1) don't use quote version macro function if you could .

%let var1   = %qscan(&varlist, i)

->

%let var1   = %scan(&varlist, i)


2)if you use %qscan() then use %unquote to get rid of mask character around macro variable.

call symput( 'MU'||left(_N_), &var1._Mean);

->

call symput( 'MU'||left(_N_), %unquote(&var1.)_Mean);



Ksharp

andrew0845
Calcite | Level 5

Problem was solved by Xia's suggestion!

Thanks for suggestions from others as well!

Andrew

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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