BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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!
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Peter_C
Rhodochrosite | Level 12
Scott
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).
peterC
Ksharp
Super User
>can choose random observations


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

[pre]
data random;
set sashelp.shoes;
if ranuni(0) ge .2 ;
run;
[/pre]



Ksharp

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 916 views
  • 0 likes
  • 4 in conversation