Help using Base SAS procedures

CALL SYMPUT problem

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 107
Accepted Solution

CALL SYMPUT problem

Dear All,

 

I am trying to save parameters as macro value. I have a variable called beta with values 1-8, represented beta1 - beta8. I would like to save each betaas as a macro value called 1bar-8bar, but I am having trouble with the naming of the variable 'ibar' in the symput statement: 

 

How could I achieve this or similar result?

 

*store the estimated parameters;
data _null_;
 set t0;
do i= 1 to 8;
if beta = i then 
 call symput('ibar', Estimate);
end;
run;

Accepted Solutions
Solution
‎04-06-2018 11:02 AM
Super User
Super User
Posts: 9,601

Re: CALL SYMPUT problem

Post some test data, I can't see anything from that code.  Also, why do you want to put things into macro paramters?  Datasets are for data.  You cannot have macro variables (or any variables) called Xbar, where X is a number, this is invalid as variables need to start with a non-numeric value.  Also, if you have multiple rows, then ibar may get overwritten each time.  Of course without data I can't say for sure.  Perhaps post test data, and what you want to see as 100% sure there is a better method.

View solution in original post


All Replies
PROC Star
Posts: 1,845

Re: CALL SYMPUT problem

[ Edited ]

Try something like-->

data _null_;
 set t0;
do i= 1 to 8;
if beta = i then 
 call symput(cats('ibar',i), Estimate);
end;
run;
Solution
‎04-06-2018 11:02 AM
Super User
Super User
Posts: 9,601

Re: CALL SYMPUT problem

Post some test data, I can't see anything from that code.  Also, why do you want to put things into macro paramters?  Datasets are for data.  You cannot have macro variables (or any variables) called Xbar, where X is a number, this is invalid as variables need to start with a non-numeric value.  Also, if you have multiple rows, then ibar may get overwritten each time.  Of course without data I can't say for sure.  Perhaps post test data, and what you want to see as 100% sure there is a better method.

Super User
Posts: 23,778

Re: CALL SYMPUT problem

You cannot start with a macro variable name with a number per the naming rules. If you do _ibar or bari instead, either would likely work. 

 


1    %let 8bar=2;
ERROR: Expecting a variable name after %LET.
2    %put &8bar.;
&8bar.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 188 views
  • 0 likes
  • 4 in conversation