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;

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!

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.

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