BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jibyjacob
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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&current;

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.

View solution in original post

7 REPLIES 7
Reeza
Super User

Please post what your current data looks like and what your output would look like.

Ksharp
Super User

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 &current &last;

data want;
 set have;
  &current = &last ;
run;
jibyjacob
Fluorite | Level 6
Thanks Mate
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

jibyjacob
Fluorite | Level 6

Thanks mate. I figured it out..

Astounding
PROC Star

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&current;

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.

jibyjacob
Fluorite | Level 6
Thank a lot..

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1326 views
  • 1 like
  • 5 in conversation