BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jennie
Calcite | Level 5

Hi,

I have a dataset with 96 variables and 28 observations per variable.

I would like to run the nlp procedure for each variable.

I am having difficulty doing so. (I am very new to SAS)

The equation and data are the same for each run of nlp procedure. I just need to change one variable (called certain) each run through.

In the end I would like to have 96 different estimates for alpha and gamma.

I have set up the nlp proc in a macro with an input variable.

I am not sure how to get the variables that I need from the data set one at a time and pass them into the macro.

Please help!

I have included what I am trying, unsuccessfully, to do below....

THanks, Jen

/* This is the macro called nlp test

     the variable 'certain' needs to change 96 times

     THe equation works if I run it using one variable, the issue is when i try to loop through multiple variables...*/

%macro nlptest(certain);

proc nlp data=Work.Prospect;

lsq z;

parms alpha=1, gamma=1;

bounds 0.0001 < gamma < 2, 0.0001 < alpha < 2;

       weight = (nn_p1 ** gamma) /( ( (nn_p1 ** gamma) + (1-nn_p1) ** gamma) ** (1/gamma) );

       value1 = nn_z1 ** alpha;

       value2 = nn_z2 ** alpha;

          z  = (((weight * value1 + (1-weight) * value2) ** (1/alpha)) - &certain)  / &certain;

run;

%mend nlptest;

/*HERE IS WHERE I START TO RUN INTO TROUBLE..... */

data array1;

set work.suregain; /* This data set contains the 96 variables I would like to loop through and pass into the macro for the nlp proc. */

    array sure{*} _numeric_;  /*I amk trying to create an array of the variables I need to pass to the macro */

    input sure{*};

    do i=1 to 96;

    %nlptest(sure{i});  /*Macro will not accept this as a value*/

    end;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Or

You might want to try call execute and the dictionary table, so you get the variable name as an argument.

data _null_;
 set sashelp.vcolumn(where=(libname='WORK' memname='SUREGAIN' xtype='num'));
 call execute('%nlptes('||strip(name)||')');
run;

Ksharp

View solution in original post

3 REPLIES 3
Reeza
Super User

You might want to try call execute and the vname function so you get the variable name as an argument.

Ksharp
Super User

Or

You might want to try call execute and the dictionary table, so you get the variable name as an argument.

data _null_;
 set sashelp.vcolumn(where=(libname='WORK' memname='SUREGAIN' xtype='num'));
 call execute('%nlptes('||strip(name)||')');
run;

Ksharp

jennie
Calcite | Level 5

Thank you for your help!

I really I appreciated it, I am feeling so lost trying to learn this stuff!!

Smiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 838 views
  • 3 likes
  • 3 in conversation