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
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.