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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

5 REPLIES 5
Ksharp
Super User

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;

mtastan
Calcite | Level 5

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

cheers.

user24feb
Barite | Level 11

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 :-).

mtastan
Calcite | Level 5

Yes, it works thanks

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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