DATA Step, Macro, Functions and more

Saving macro values

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 107
Accepted Solution

Saving macro values

Dear All,

 

I am trying to save parameters as a macro:

data t0;
length Parameter $15;
input Parameter $ Estimate;
datalines;
Intercept 1132
;
run;

*store the estimated parameters;
data _null_;
 set t0;
 if Parameter = "Intercept" then 
 call symput('Ibar', Esimate);
run;

%put &Ibar;

 

 

I get the message that IBar was not saved properly:

SYMBOLGEN: Macro variable IBAR resolves to .

 

Why can"t I save the value?

 

 


Accepted Solutions
Solution
‎04-06-2018 09:38 AM
Super User
Posts: 9,890

Re: Saving macro values

Your corrected code, posted with the "little running man", looks like this:

data t0;
length Parameter $15;
input Parameter $ Estimate;
datalines;
Intercept 1132
;
run;

*store the estimated parameters;
data _null_;
set t0;
if Parameter = "Intercept" then call symput('Ibar', Estimate);
run;

%put &Ibar;

You can see the advantages of posting code in the right manner.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Posts: 9,890

Re: Saving macro values

Look at your second parameter of call symput. It's misspelled.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Respected Advisor
Posts: 2,825

Re: Saving macro values

Is that exactly how you typed it, with many SAS commands on the same line?

 

Not only is this a bad practice, but I believe it is why the commands fail.

 

You need to put each command on it's own line

 

Furthermore the line that reads 

Intercept 1132

 

should be on a line without a semicolon, and the semicolon that follows should be on the next line. 

 

Then, you need to spell the variable name exactly the same in both the DATA T0; step, and in the DATA _NULL_; step.

--
Paige Miller
Solution
‎04-06-2018 09:38 AM
Super User
Posts: 9,890

Re: Saving macro values

Your corrected code, posted with the "little running man", looks like this:

data t0;
length Parameter $15;
input Parameter $ Estimate;
datalines;
Intercept 1132
;
run;

*store the estimated parameters;
data _null_;
set t0;
if Parameter = "Intercept" then call symput('Ibar', Estimate);
run;

%put &Ibar;

You can see the advantages of posting code in the right manner.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 107

Re: Saving macro values

[ Edited ]
Posted in reply to KurtBremser

Thanks for the help. This was copy-pasted in the "running man" line by line as suggested below. I don't know why the display changed after posting. 

 

 

Super User
Posts: 9,890

Re: Saving macro values

Always post into the code windows while they are open (Pop-up). Posting into the field within the main posting window eats linefeeds.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 105 views
  • 0 likes
  • 3 in conversation