population is the field-name in data-file (say, tab). MVAR<-population takes data (in the column of population) rather than field-name as done in SAS: %let MVAR=population; In the following r-program, for instance, I cannot use ... tab$MVAR...or simply MVAR itself since MVAR is defined as "population" with double quotes if using MVAR<-c("population")
On Wednesday, February 3, 2016 11:54 AM, Duncan Murdoch <murdoch.dun...@gmail.com> wrote: On 03/02/2016 12:41 PM, Amoy Yang via R-help wrote: > There is a %LET statement in SAS: %let MVAR=population; Thus, MVAR can be >used through entire program. > In R, I tried MAVR<-c("population"). The problem is that MAVR comes with > double quote "...." that I don't need. But MVAR<-c(population) did NOT work > out. Any way that double quote can be removed as done in SAS when creating > macro_var? > Thanks in advance for helps! R doesn't have a macro language, and you usually don't need one. If you are only reading the value of population, then MAVR <- population is fine. This is sometimes the same as c(population), but in general it's different: c() will remove some attributes, such as the dimensions on arrays. If you need to modify it in your program, it's likely more complicated. The normal way to go would be to put your code in a function, and have it return the modified version. For example, population <- doModifications(population) where doModifications is a function with a definition like doModifications <- function(MAVR) { # do all your calculations on MAVR # then return it at the end using MAVR } Duncan Murdoch [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.