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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 761 views
  • 3 likes
  • 2 in conversation