First, you hit ctrl-r to start recording. Then, you do whatever it is you want your macro to do. Then, you hit ctrl-r again to stop recording.
So, for example, let's say I want to make a macro to select a whole page on the trade screen. First, I go to the trade screen and find a whole page of things I want to trade (this step is not, strictly, necessary, but it's helpful). Next, I hit ctrl-r. Now, I select a whole page of things, in this case by alternating between hitting down and ENTER 16 times, then I hit ctrl-r again. The macro is now recorded.
At this point, I can hit ctrl-p, and the game will do exactly the same button presses as I did. In the above example, at this point hitting ctrl-p will alternate between hitting down and ENTER 16 times. This will continue to be the case until I exit Dwarf Fortress entirely (including closing the program), hit ctrl-r again (which would start recording a new macro), or load a different, pre-saved macro with ctrl-l.
Speaking of pre-saved macros, if you hit ctrl-s, the game will open up a little box in which you can type in a name. This will save the currently-active macro with that name. You can then reload that macro at any time by pressing ctrl-l, scrolling through the list that pops up, and hitting ENTER, at which point hitting ctrl-p will run that macro.
The short of it is, you tell the game to record your following actions as a macro, you do the actions you want the macro to do, then you tell it to stop recording. It's really fairly intuitive once you just start doing it.