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

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.

 

 

 

1 ACCEPTED SOLUTION
15 REPLIES 15
Cathy
Obsidian | Level 7

%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.  

FreelanceReinh
Jade | Level 19

Hi @Cathy,

 

The plot request should read y*v&i rather than y*i.

Cathy
Obsidian | Level 7

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.

Cathy
Obsidian | Level 7
I got this...%questions((start=3,stop=5)

it print out...finally
Cathy
Obsidian | Level 7
Thanks a lot again. This helps me a lot too
Cathy
Obsidian | Level 7
Thanks a lot, I got it finally and giving me a good direction.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Cathy
Obsidian | Level 7

thank you, but I need to use macro for this.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Cathy
Obsidian | Level 7

I am studying little SAS book and preparing to get certificate too. That's why I need to know macro too. Thank you. 

Cathy
Obsidian | Level 7
Thank you so much too.
stat_sas
Ammonite | Level 13

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 15 replies
  • 1423 views
  • 5 likes
  • 5 in conversation