Hi everyone.
I have tried several different ways to get this to work. I can code it fine, but the current version of the code is really long and ugly. I know an array can fix it, but I cannot get it to work.
I have 38 monthly transaction fields labeled purch_201001 to purch_201302. I know that some of the data is invalid. I have a field called TARGET that identifies the last valid month of data. IE if the last valid month for the customer was Dec 2012, then TARGET=purch_201212. I need an array that will write over the remaining transaction fields with ".". In the example, it would overwrite purch_201301 and purch_201302, but the TARGET varies for other customers.
written out in long form it would be... if TARGET=purch_201212 then purch_201301=. and purch_201302=.; else if TARGET=purch_201301 then purch_201302=.; etc etc for all 38 months.
I know it's fairly simple array... but for whatever reason, I can't get it to work.
Any help is greatly appreciated!!!!
Thank you!
SS
This should work (untested) :
data want;
set have;
array purch{*} purch_:;
do _n_ = 1 to dim(purch);
if upcase(vname(purch{_n_})) > upcase(target) then call missing(purch{_n_});
end;
run;
PG
Perfect! Just had to make a small adjustment missing TARGETs and its working great.
Thanks!!!!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.