DATA Step, Macro, Functions and more

How to move data between existing datasets at 1st of every month

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

How to move data between existing datasets at 1st of every month

I have a frequently updated database of email id's of unsubscribed users and I need to move them from a Master database to the Unsubscribed email database on the 1st day of every month. 

 

I started SAS programming only about 2 weeks ago so I have a couple of question on how do I go about this. Please bear in mind that I am still studying to be a bit fluent with the array and macro functions and concepts. 

 

1. Can I create a Macro that frequently checks and moves the emails on the 1st day of every month, from insurance_master sheet to unsubscribed sheet??

2. Or should I create an Array.
3. Or use an Array within the Macro?

 

I have 2 datasets:

1 - darshik.insurance_master {variables email & type } type is char variable with the indutsry type info.

2 - darshik.unsubscribed {variables email & unsb } Unsb is numeric variable with values 0 & 1

 

I am unable to put up any code as an example as I am thoroughly confused at this point on where and how to begin. So far I have only removed the duplicates from both the files.

 

 


Accepted Solutions
Solution
‎02-26-2018 04:12 PM
PROC Star
Posts: 8,115

Re: How to move data between existing datasets at 1st of every month

If you only have to remove emails (from the insurance_master) that are also on the unsubscribe dataset with an unsb value of 1, then you could simply run the following at on the first of every month:

proc sort data=insurance_master;
  by email;
run;

proc sort data=unsubscribed;
  by email;
run;

data updated_insurance_master (drop=unsb);
  merge insurance_master unsubscribed;
  by email;
  if not unsb eq 1;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
PROC Star
Posts: 1,190

Re: How to move data between existing datasets at 1st of every month

Welcome to the forum and to the wonderful world of SAS Programming Smiley Happy

 

With problems like this, it is often of great help to us if you post some sample of your data, or some data that resembles the data you have on hand. 

Occasional Contributor
Posts: 6

Re: How to move data between existing datasets at 1st of every month

Thank you for the welcome and your response.

 

I absolutely agree that posting some form of code is always helpful to provide more insight. However, I couldn't find a way to write something so I didn't have any existing code to provide.

 

However, I am doing some more research and trying and come up with a program, and I will post it here as soon as I can Smiley Happy 

Solution
‎02-26-2018 04:12 PM
PROC Star
Posts: 8,115

Re: How to move data between existing datasets at 1st of every month

If you only have to remove emails (from the insurance_master) that are also on the unsubscribe dataset with an unsb value of 1, then you could simply run the following at on the first of every month:

proc sort data=insurance_master;
  by email;
run;

proc sort data=unsubscribed;
  by email;
run;

data updated_insurance_master (drop=unsb);
  merge insurance_master unsubscribed;
  by email;
  if not unsb eq 1;
run;

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 6

Re: How to move data between existing datasets at 1st of every month

Is there a way to create a macro for this piece of code?

 

On a side note, how does the "If not" statement work? Although I have used the If-then-else statements now and then, I haven't yet come across of 'If not'. Sorry if my questions come across as silly, I am still catching up on a lot of things in SAS. Thank you for the response by the way Smiley Happy

PROC Star
Posts: 8,115

Re: How to move data between existing datasets at 1st of every month

Just another way of saying:

  if unsb ne 1;

Art, CEO, AnalystFinder.com

 

 

Super User
Posts: 22,874

Re: How to move data between existing datasets at 1st of every month

You should also look into how to UPDATE a data set using either a data set or PROC SQL. 

 

Occasional Contributor
Posts: 6

Re: How to move data between existing datasets at 1st of every month

Thank you! I will do some quick research on this as well.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 152 views
  • 0 likes
  • 4 in conversation