Tuesday, February 19, 2013

Test your macro

Macro programming is generally considered an advanced topic. But during the training at Bancova I've found it easy to learn the basic concepts, as well as simple implementation for daily task.
Here is a short presentation I gave in the summer, a quick test of your macro skills:


You can also watch my video as you go through the ppt above.
Now I want to show you two examples of using the macro.
The first "setr" macro will generate a column of random number in the datasets.
https://gist.github.com/4083348
With the first "setr", the second "setcat" macro can create a categorical variable with the assigned number of observations for each group in random sequence. This is good for data simulation.
https://gist.github.com/4083405
For instance, if in the dataset "all" with 10 observations, two variables "Subjid" and "Treatment", we want to create a new dataset "dis" with a new variable "Reasons" based on the "all".

We can simply use the following code:
%setcat(indsn=all, outdsn=dis, rn=0, varname=Reasons, len=40,
cat=Disease Progression|Adverse event|Subject Choice|Investigator discretion,
ncat=2|2|3|3);
Then we will get the new dataset "dis" we want like this:

Easy enough, right? Thanks for coming to my blog! See you next time!

No comments:

Post a Comment