if this is only qtr/monthly intervals, it might be a good case to demonstrate array handling. SAS/IML would also simplify the resultant solution. What follows uses only a data step and assumes the monthly data arrive in month order within each company
data progressive_stddevs ; do item= 1 by 1 until( last.company ) ; set your_data ; by company ; array cogX(1200) ; * 1200 months, probably enough per company? ; cogX(item) = cogsq ; n_cogs = n( of cogX(*) ) ; if n_cogs > 1 then COGSTD = std( of cogX(*) ) ; output ; end ; drop cogX: ; run ;
the array is filled progressively until end of the company, when it will be emptied by restarting the data step iteration
The STD() function ignores empty cells in the array
... View more