BookmarkSubscribeRSS Feed
jstuartys
Calcite | Level 5

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

2 REPLIES 2
PGStats
Opal | Level 21

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
jstuartys
Calcite | Level 5

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

Thanks!!!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 644 views
  • 1 like
  • 2 in conversation