Hi,
How can I scan through an array and put the last value of the array into another variable..
Have
value1 value2 value3 value4 value5 value6
xa xm bb
cc ad mn xy
xo
xe an th ty pb kl
WANT:
new
bb
xy
xo
kl
Thanks
I suppose there maybe better approaches, but you can always do it reversely:
data have;
infile cards truncover;
input ( value1 value2 value3 value4 value5 value6) (:$2.);
array v value6 value5 value4 value3 value2 value1;
do over v;
if not missing (v) then do; new=v;leave;end;
end;
cards;
xa xm bb
cc ad mn xy
xo
xe an th ty pb kl
;
Haikuo
UPdate: here is another option, better, in a way that you don't need to define array() elements explicitly.
data have;
infile cards truncover;
input ( value1 value2 value3 value4 value5 value6) (:$2.);
array v value:;
new=v(dim(v)-cmiss(of v(*)));
cards;
xa xm bb
cc ad mn xy
xo
xe an th ty pb kl
;
I suppose there maybe better approaches, but you can always do it reversely:
data have;
infile cards truncover;
input ( value1 value2 value3 value4 value5 value6) (:$2.);
array v value6 value5 value4 value3 value2 value1;
do over v;
if not missing (v) then do; new=v;leave;end;
end;
cards;
xa xm bb
cc ad mn xy
xo
xe an th ty pb kl
;
Haikuo
UPdate: here is another option, better, in a way that you don't need to define array() elements explicitly.
data have;
infile cards truncover;
input ( value1 value2 value3 value4 value5 value6) (:$2.);
array v value:;
new=v(dim(v)-cmiss(of v(*)));
cards;
xa xm bb
cc ad mn xy
xo
xe an th ty pb kl
;
Thanks Hi,
Unfortunately ,the system is not showing the Correct option..I will update it a lil later
Regards
hi,
I was curious why did you put the array items in the reverse order in the first method????????/
Thanks
So when looping through array, it starts from value6 to value1. Of course you don't have to do that, cause you can always loop it from the END to START, it didn't occur to me until I posted up.
I was thinking if array goes from end to start it would give us
new
xa
cc
xo
xe
Thnkx
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.
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.