i created 2 macro variables in sas code using %let option.
data sasdata1.dataone; set sasdata1.dataone ; %let week=1; %let sum=0; i=1 53; %let sum= _w&week._nrx + &sum.; week=&week+1; end; drop i; week=&week; sum=&sum.; run;
the value of week variable remains 1 after loop has executed. correct way change value of macro variables?
if week variables next each other in dataset, may want consider macro-less approach:
data sasdata1.dataone; set sasdata1.dataone; sum = sum(of _w1_nrx--_w53_nrx); *double dash means columns next each other _w1_nrx first , _w53_nrx last; run;
if week variables end week number, not need next each other:
data sasdata1.dataone; set sasdata1.dataone; sum = sum(of _w1-_w53); *single dash implies suffix numerically increasing; run;
clean , easy.
Comments
Post a Comment