I need to create a macro. I have dataset having variables from v1 to v7 (independent variables) and y for response. the number of predictors using "varnum" for execution.
Create the macro for each predictors, with simple linear regression and gplot. Please help how I can start with coding. Thanks.
Very simple, but may lead you in the right direction:
%macro regressions (varnum);
%do i = 1 %to &varnum;
proc reg;
model y=v&i;
run;
%end;
%mend;
Very simple, but may lead you in the right direction:
%macro regressions (varnum);
%do i = 1 %to &varnum;
proc reg;
model y=v&i;
run;
%end;
%mend;
%macro regressions (varnum);
%do i = 1 %to &varnum;
proc reg data=new;
model y=v&i;
run;
proc gplot data=new;
plot y*i/vaxis= 0 to 1 by 0.1;
run;
%end;
%mend;
%regressions(5)
I got it for regression. But how can I use proc gplot ? It does not work with macro. It shows that at least one plot or bubble statement must be given.
Thank you.
I have a question regarding using this code;
for example if I want to create start at 3 and stop at 5.
%macro questions(start=3,stop=5);
%do i = &start %to &stop;
proc reg data=new;
model y=v&i;
run;
%do j=&i+1 %to &stop+1;
proc gplot data=new;
plot v&i*v&j;
run;
%end;
%end;
%mend;
%questions(3)
Please help me this too. Thanks.
Hi,
Well, your problem seems to lie in the way you have set your data up - i.e. wide rather than long. I am not familiar with proc reg, so am guessing a bit on syntaxt here, but all procedures are built to allow by group processing - which is both faster, and more efficient, plus easier to maintain. To use this however your data needs to be long data rather than wide. Don't confuse what data you may use in an output review file (which is likely to need transposing) with data you use for your programming, the two can be totally different. An example below shows how to normalise your data, and then use a by grou - see how much simpler the code is, easier to maintain, no macro at all just plain base SAS - note that you have not provided any test data (in the form of a datastep) so this is just an example:
proc transpose data=have out=t_have; by <id variables>; /* Replace with your id variables */ var v:; run; proc reg data=t_have; by _name_; model y=col1; run;
thank you, but I need to use macro for this.
Why? There is never a "need" to use any tool, use the one thats fits the job best? Macro language is designed as a code generation toolkit, nothing more, Base SAS is the programming language.
I am studying little SAS book and preparing to get certificate too. That's why I need to know macro too. Thank you.
If you are looking for predictors contributing more in the model then you can try selection criteria based on rsquare to flag predictors for the final model:
proc reg data=have;
model y=v:/selection=rsquare;
plot r.*(p. v: );
plot student.*obs. / vref=3 2 -2 -3;
run;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.