1

This is a SAS code using the macro variable but I am trying to do this in R. Is it possible to use Macro in R?

%macro LOOCV;*Macro Name is LOOCV;
*Take one row out at a time, and there are 295 rows;
%do i = 1 %to 59;
data epilepsy_long_cv;
   set epilepsy_long; *Find ith row and set weekly rate to missing, so the model building doesnt use ith observation;
   if ID = &i then Weeklyrate=.; 
run;

proc Reg Data=epilepsy_long_cv noprint;*Use noprint to suppress output;
   model WeeklyRate = Age Time Trt;
   output out=work.pred  p=predict;
run;
quit;
Stacy
  • 19
  • 1
  • Might help https://stackoverflow.com/questions/28484072/how-do-i-use-a-macro-variable-in-r-similar-to-let-in-sas – NelsonGon Jan 26 '19 at 19:35
  • 1
    You cant't use macros in r you have to learn to think differently i R and it can be very confusing. Some taks that are easy in SAS become difficult in r but the other way holds also. Mostly I think that the substitude for macros is to write function. Changing to r from SAS can be quite confusing. – xhr489 Jan 26 '19 at 21:06
  • 1
    It would help if you could describe what the input looks like (preferably by sharing an example using `dput(YOUR_DATA_HERE`), what the macro needs to do, and what the output should be. I am sure it's possible in R, but it will be hard to help without more information. – Jon Spring Jan 26 '19 at 21:23

1 Answers1

2

In R, you write user functions instead of SAS macros. I.e. if you wish to replicate proc reg (SAS) for a linear modelling in R, you have to find an R equivalent to this procedure and parametrise it equivalently. I assume in R you are looking for lm and the predict method.

Vojta F
  • 534
  • 3
  • 17