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
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;
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;
Many Thanks for quick reply. Yes this is what I was looking for.
cheers.
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 :-).
Yes, it works thanks
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.