Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Creating macro values efficiently

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-06-2018 02:34 PM
(1084 views)

Dear All,

I am trying to save parameters as a macro value. Then later on in my code I refer to the macro value. Below I present how I create the macro value for the Intercept. The issue is that I have many parameters (more than displayed here) and I would like to automate the creation of the macro values. Is there a good way to do this?

```
data parameters;
length parameter $15;
input parameter $ Estimate;
datalines;
Intercept 2739.317514
year_2011 94.417557
year_2012 42.503822
year_2013 282.512589
age_gr_1 -1363.790104
age_gr_2 -1463.203183
age_gr_3 -1536.600297
age_gr_4 -1257.557011
age_gr_5 -1320.657019
age_gr_6 -1203.189233
age_gr_7 -939.516061
age_gr_8 -1062.720370
age_gr_9 -1053.240621
age_gr_10 -748.843390
age_gr_11 -426.568952
age_gr_12 -488.670104
age_gr_13 191.591615
age_gr_14 302.807785
age_gr_15 805.862238
age_gr_16 862.097090
age_gr_17 1010.055915
age_gr_18 1041.829821
age_gr_19 704.449366
age_gr_0 0.000000
;
run;
data parameters;
set parameters;
if parameter = Intercept then
call symput('Interceptbar', Estimate);
run;
```

13 REPLIES 13

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Efficiency depends on what you want to do with the paramaters.

Maybe that creating them in a sas dataset is more efficient then creating macro variables.

Please describe your work in more details.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Converting floating point numbers to text will lose some precision.

What are you going to do with the macro variables?

If you want to make macro variables whose name is contained in data then that is simple.

```
data _null_;
set parameters;
call symputx(parameter,put(estimate,best32.));
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Tom, I want the macro variables to contain the appropriate Estimate value.

So Intercept=2739.317514,

year_2011=94.417557, etc.

So Intercept=2739.317514,

year_2011=94.417557, etc.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Each of your parameters has an Estimate, and there is an intercept. Is this going to be used in some mathematical formula? There are ways to turn this type of situation into that mathematical formula without ever using a macro. The most obvious solution is PROC SCORE.

Do not do this via macros unless alternative solutions are not obvious, or difficult to use.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I am trying to bootstrap the parameters. Essentially this is what I need to calculate for each parameter:

```
proc sql;
select sum(Intercept<=&Interceptbar)/count(Intercept) into :z0bar
from t2;
quit;
data _null_;
z0 = probit(&z0bar);
zalpha = probit(&alpha1);
p1 = put(probnorm(2*z0 - zalpha)*100, 3.0);
p2 = put(probnorm(2*z0 + zalpha)*100, 3.0);
output;
call symput('a1', p1);
call symput('a2', p2);
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

No need to move the data into text for that.

```
proc sql;
select sum(a.Intercept<=b.estimate)/count(a.Intercept)
into :z0bar trimmed
from t2 a
, parameters b
where b.parameter='Intercept'
;
quit;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Tom, Thanks for the response. This is great, but i still need a solution to running this code above automatically on all parameters. The only solution I have found is to create macro variables for each parameter and running an array on it.

Sort of like this:

%let Intercept=param1;

%let year_2011=param2;

etc.

and then doing a do-loop for the array. This is just as time-consuming as my original idea. Am I missing something? Is there a better way?

Sort of like this:

%let Intercept=param1;

%let year_2011=param2;

etc.

and then doing a do-loop for the array. This is just as time-consuming as my original idea. Am I missing something? Is there a better way?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@GKati wrote:

Hi Tom, Thanks for the response. This is great, but i still need a solution to running this code above automatically on all parameters. The only solution I have found is to create macro variables for each parameter and running an array on it.

Sort of like this:

%let Intercept=param1;

%let year_2011=param2;

etc.

and then doing a do-loop for the array. This is just as time-consuming as my original idea. Am I missing something? Is there a better way?

I have no idea what your process is so I cannot comment on its efficiency.

I was just commenting on the fact that moving floating point numbers from dataset variables (where they are stored as floating point numbers) into macro variables (where they are stored as text strings) and then using the macro variables in calculations will lose precision. You should be able to use the dataset variable directly for most things. Like the example SQL were you were counting how many times the value was exceeded.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@GKati wrote:

I am trying to bootstrap the parameters. Essentially this is what I need to calculate for each parameter:

It is completely unnecessary to assign these values to macro variables to do a bootstrap.

Please see the method provided by @Rick_SAS on how to do a bootstrap without macros:

https://blogs.sas.com/content/iml/2016/08/10/bootstrap-confidence-interval-sas.html

Also, SAS user @Ksharp has written code to do this for Logistic Regression, it ought to be easy to change this for any type of regression. Again, he does not assign these values to macro variables.https://communities.sas.com/t5/Base-SAS-Programming/10-FOLD-CROSS-VALIDATION-amp-BOOTSTRAPPING/m-p/4...

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks for your response. These bootstraps are not what I am trying to do. I need a bias-adjusted percentile method for CI's. This is my source:

https://stats.idre.ucla.edu/sas/faq/how-can-i-bootstrap-estimates-in-sas/

That is to say, it is not the bootstrapping itself that I am stuck with but the bias-adjustment and doing it automatically for all parameters.

EDIT: The big difference is that these codes calculate one parameter many times over. I need to calculate many variables many times over, so it needs to be automated somehow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@GKati wrote:

Thanks for your response. These bootstraps are not what I am trying to do. I need a bias-adjusted percentile method for CI's. This is my source:

https://stats.idre.ucla.edu/sas/faq/how-can-i-bootstrap-estimates-in-sas/

That is to say, it is not the bootstrapping itself that I am stuck with but the bias-adjustment and doing it automatically for all parameters.

EDIT: The big difference is that these codes calculate one parameter many times over. I need to calculate many variables many times over, so it needs to be automated somehow.

And yet, earlier you told us "I am trying to bootstrap the parameters", which is not what you are telling us now, you have now added different and significant information. If you had told us this in the first post you made, we might have pointed you to the answer already.

I believe Rick has written a bias adjusted bootstrap example code. Why don't you use some search engine to see what you can find? Or maybe Rick will stop in and give us the link.

And anyway, whatever your needs are, you haven't listened to anyone, who keep telling you: macros are not needed. So let me make a point here for emphasis: using macro variables are you stated is not necessary at all.

--

Paige Miller

Paige Miller

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.