BookmarkSubscribeRSS Feed
GKati
Pyrite | Level 9

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
Shmuel
Garnet | Level 18

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.

Tom
Super User Tom
Super User

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;
GKati
Pyrite | Level 9
Hi Tom, I want the macro variables to contain the appropriate Estimate value.

So Intercept=2739.317514,
year_2011=94.417557, etc.
PaigeMiller
Diamond | Level 26

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
Reeza
Super User

If you have estimates that you want to apply to new data, ie score data, make sure to see if the PROC you're using has the CODE statement instead or a SCORE option. Those are infinitely easier to use and manage. 

GKati
Pyrite | Level 9

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;
Tom
Super User Tom
Super User

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;
GKati
Pyrite | Level 9
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?
Tom
Super User Tom
Super User

@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.

PaigeMiller
Diamond | Level 26

@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
GKati
Pyrite | Level 9

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.  

Reeza
Super User

Are you using BY GROUP Processing? Did you read Don't be Loopy - Simulation the SAS Way by David Cassell? I think those will point you in the direction you want and have ample examples.

PaigeMiller
Diamond | Level 26

@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

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
  • 13 replies
  • 1361 views
  • 4 likes
  • 5 in conversation