DATA Step, Macro, Functions and more

inserting an array of macro variables in proc reg statement

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

inserting an array of macro variables in proc reg statement

Hello everyone,

I am running quantile regression where a simple sas code is like

PROC QUANTREG DATA=dataExample;

MODEL y=x1 / QUANTILE=0.1 0.3 0.5 0.7;

RUN;


Here, I want to replace QUANTILE values in proc statement by those that I previously generate as a macro variable from the code below

proc sql noprint;

select count(*)

into :NObs

from quants;

select G

into :q1-:q%let(left(Nobs))

from quants;

quit;

Now, how I can insert values from q1, q2, ..., q(last) in the proc quantreg statement above. I do not want to do this manually because number of quantiles are keep changing

Many Thanks


Accepted Solutions
Solution
‎01-16-2015 06:40 AM
Super User
Posts: 9,682

Re: inserting an array of macro variables in proc reg statement

How about this:

proc sql noprint;

select G

into : list separated by ' '

from quants;

quit;

PROC QUANTREG DATA=dataExample;

MODEL y=x1 / QUANTILE= &list ;

RUN;

View solution in original post


All Replies
Solution
‎01-16-2015 06:40 AM
Super User
Posts: 9,682

Re: inserting an array of macro variables in proc reg statement

How about this:

proc sql noprint;

select G

into : list separated by ' '

from quants;

quit;

PROC QUANTREG DATA=dataExample;

MODEL y=x1 / QUANTILE= &list ;

RUN;

New Contributor
Posts: 3

Re: inserting an array of macro variables in proc reg statement

Many Thanks for quick reply. Yes this is what I was looking for.

cheers.

Super Contributor
Posts: 336

Re: inserting an array of macro variables in proc reg statement

You probably do not need the array. Try:

proc sql noprint;
select count(*) into :NObs from quants;

Select G into :q Separated By ' ' from quants;
quit;

And:

PROC QUANTREG DATA=dataExample;
MODEL y=x1 / QUANTILE=&q.;
RUN;

.. and ksharp was much quicker :-).

New Contributor
Posts: 3

Re: inserting an array of macro variables in proc reg statement

Yes, it works thanks

Super User
Super User
Posts: 7,407

Re: inserting an array of macro variables in proc reg statement

Or:

data _null_;

     set quants end=last;

     if _n_=1 then call execute('proc quantreg data=dataExample; model y=x1 / quantile='||strip(g));

     else call execute(' '||strip(g));

     if last then call execute('; run;');

run;

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 403 views
  • 6 likes
  • 4 in conversation