Desktop productivity for business analysts and programmers

Data Step

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Data Step

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


Accepted Solutions
Solution
‎04-20-2016 01:28 PM
Super User
Posts: 5,366

Re: Data Step

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


All Replies
Super User
Posts: 19,157

Re: Data Step

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

Super User
Posts: 9,867

Re: Data Step

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;
Occasional Contributor
Posts: 7

Re: Data Step

Thanks Mate
Super User
Super User
Posts: 7,720

Re: Data Step

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.

Occasional Contributor
Posts: 7

Re: Data Step

Thanks mate. I figured it out..

Solution
‎04-20-2016 01:28 PM
Super User
Posts: 5,366

Re: Data Step

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.

Occasional Contributor
Posts: 7

Re: Data Step

Thank a lot..
☑ This topic is solved.

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

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