Hi,
I am working on automating a process, this includes retrieving data from numerous outputs. I find the following a challenge and need your help. I need to sum up premiums on a monthly basis for the current month and I have macro variables that calculates current month.
Can you please help me create a datastep that sum up premiums for current month, in this scenario it is March 2016. there will a new variable for April 2016 next month ( EP201604).
Appreciate your help.
Example.
EP201601 EP201602 EP201603
545 5454545 5454545
4545 5454545 5454545
You mention that you have calculated a macro variable that indicates the current month ... but you don't show us what that looks like. So I will take the easiest route, and assume that you have (or could create) the equivalent of:
%let current = 201603;
And that your process would automatically change so that next time you would get:
%let current = 201604;
Then summing the proper variable might be as simple as:
proc summary data=have;
var EP¤t;
output out=want sum=;
run;
There are probably some differences between this and what you actually are working with right now, but this would be the general idea of how to approach the problem.
Please post what your current data looks like and what your output would look like.
It sounds like you need create a appropriate macro variable.
%let current=EP%sysfunc(today(),yymmn6.);
%let last=EP%sysfunc(intnx(month,%sysfunc(today()),-1),yymmn6.);
%put ¤t &last;
data want;
set have;
¤t = &last ;
run;
That dataset strcuture is not a good storage method from a programming point of view. Work with normalised data, then transpose at the end, will make your life a lot easier. Show your data too, as no idea why there would be two observations for each:
Period Total
EP201601 545
EP201602 5454545
EP201603 5454545
...
Is a far easier structure to work with.
Thanks mate. I figured it out..
You mention that you have calculated a macro variable that indicates the current month ... but you don't show us what that looks like. So I will take the easiest route, and assume that you have (or could create) the equivalent of:
%let current = 201603;
And that your process would automatically change so that next time you would get:
%let current = 201604;
Then summing the proper variable might be as simple as:
proc summary data=have;
var EP¤t;
output out=want sum=;
run;
There are probably some differences between this and what you actually are working with right now, but this would be the general idea of how to approach the problem.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.