See it done in SAS and RBlog with annotated examples of code for tasks in SAS and R. sas-and-r.blogspot.