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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 629 views
  • 1 like
  • 2 in conversation