DATA Step, Macro, Functions and more

Help with macro?

Not applicable
Posts: 0

Help with macro?

I want to create a macro where I can very quickly subset my observations from the first 5 days of the month then merge this with another dataset by unique ID and compare results. Just wondering how I should be coding to create a macro where I can choose random observations based on the date variable being between the first say 5 days or 7days of each and every month.
Merging should be quite easy after that right? Sorry Im not very good with macros :x
Cheers & Thanks!
Super Contributor
Super Contributor
Posts: 3,176

Re: Help with macro?

Posted in reply to deleted_user
As has been suggested previously on this forum channel, suggest you start out first with a working SAS program to confirm the basic logic and code required (DATA, PROC steps, and within them any SAS functions needed).

Then, based on what component(s) of your code is expected to be "variable", then consider leveraging the benefits of the SAS macro facility to create an suitable process that offers desired flexibility that's needed to suit our data filtering and analysis requirements.

There are multiple approaches and SAS facilities to consider using, what with PROC SQL, PROC SORT, DATA step (using MERGE with a BY), and associated SAS functions like DAY().

Especially considering that you are not familiar with SAS macro coding (as stated in your post), it's best to define the logic/process flow, then come back to the forum for additional guidance with evolving the code-piece into a macro, as required.

Scott Barry
SBBWorks, Inc.
Valued Guide
Posts: 2,191

Re: Help with macro?

this is not the first time a request involving "macro" may just be using the wrong terminology. As here when the poster should just be asking for any program solution.
The term "macro" in excel seems to refer to the only form of processing in that environment (if "formula" is just not enough).
So those new to SAS environment may think they should use the term macro to ask about any SAS programming.
(they are certainly not ready for SAS macros at such a new-entrant stage).
Super User
Posts: 10,770

Re: Help with macro?

Posted in reply to deleted_user
>can choose random observations

You can use proc surveyselect(Art C mentioned before) or data step to do it.

data random;
if ranuni(0) ge .2 ;

Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation