Saturday, March 15, 2014

Data _null_ instead of Do Loop (SAS)

Avoiding do loop in SAS

Lets suppose I have data set like

Input Dataset:

Country Month Sales
India Jan 100
India Feb 200
US Jan 300
US Feb 500
UK Jan 150
UK Feb 350

I need separate output dataset for all the contries present in Input Dataset with cumulative sales.

Instead of counting countries and using a Do loop.
Create a dataset with distinct countries call a macro inside a datastep.

Function used:
Data _null_ , call symputx(), Call execute.

Try it out yourself then refer to code below. Can leave a feedback/suggestions in the comments.