I am currently working on converting a SAS macro into a R code. I have worked a lot on R but I am relatively new to SAS. I am having trouble understanding the SAS code for a merge command -
data dates;
merge A(keep=date rename=(date=beg))
A(keep=date firstobs= 5 rename=(date=end))
A(keep=date firstobs= 10 rename=(date=bega))
A(keep=date firstobs= 15 rename=(date=ee))
A(keep=date firstobs= 30 rename=(date=eend));
index+1;
if nmiss(beg,end,bega,eend,ee)=0;
run;
I understand that this command is joining the file A to itself 5 times. But I am not able to visualize the output. What does 'index+1' and 'if' stand for. What is the R version for this code?
I'm not quite familiar with R, but I know some SAS. I'm not sure if I would call this a macro... The output of your merged data set will depend on how your input data set looks like. Just run your code, and you'll be able to see it in your work folder...
Generally, the data step is structured like an implicit loop. The
index+1
looks like thesum
statement with the syntax: variable+expression. In this case, the value of index after +1 will be retained for another iteration.The
if
statement here contains a boolean condition (i.e. it can have the value of either True or False, but not both) to set a constraint when outputting the data step. If it's true, the current row of data will be outputted. nmiss(var1,var2,var3,...) is a function that will return the number of arguments specified insidenmiss()
that are missing. E.g. if only var1 is missing, nmiss(var1,var2,var3,...) = 1.