You don't need a macro, the same can be achieved by using Hashes--> Assuming your dataset is sorted by CAMPAIGN_GROUP_CD data _null_; if _n_=1 then do; if 0 then set CMS_STG_AGENT; dcl hash h(dataset:'CMS_STG_AGENT(obs=0)',multidata: 'y', ordered: 'y'); h.definekey('CAMPAIGN_GROUP_CD'); h.definedata('agent','capacity'); h.definedone(); end; set CMS_STG_AGENT ; by CAMPAIGN_GROUP_CD; if first.CAMPAIGN_GROUP_CD then do; h.clear(); n+1; end; rc=h.add(); if last.CAMPAIGN_GROUP_CD then h.output(dataset:'cms_group'||left(n)); run; Regards, Naveen Srinivasan
... View more