BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

;

View solution in original post

5 REPLIES 5
Haikuo
Onyx | Level 15

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

;

robertrao
Quartz | Level 8

Thanks Hi,

Unfortunately ,the system is not showing the Correct option..I will update it a lil later

Regards

robertrao
Quartz | Level 8

hi,

I was curious why did you put the array items in the reverse order in the first method????????/

Thanks

Haikuo
Onyx | Level 15

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.

robertrao
Quartz | Level 8

I was thinking if array  goes from end to start it would give us

new

xa        

cc          

xo

xe    

Thnkx    

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
  • 5 replies
  • 783 views
  • 3 likes
  • 2 in conversation