Help using Base SAS procedures

Array to null out vars in wide transaction data

Reply
New Contributor
Posts: 2

Array to null out vars in wide transaction data

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

Respected Advisor
Posts: 4,919

Re: Array to null out vars in wide transaction data

Posted in reply to jstuartys

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

PG
New Contributor
Posts: 2

Re: Array to null out vars in wide transaction data

Perfect!  Just had to make a small adjustment missing TARGETs and its working great.

Thanks!!!!

Ask a Question
Discussion stats
  • 2 replies
  • 149 views
  • 1 like
  • 2 in conversation