DATA Step, Macro, Functions and more

Arrays

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

Arrays

How can I access only one value of a column in array or suppose

X  Y

2   1

2   5

3   6

 I need output as

X Y  Z

2  1  2

2  5 10

3  6  12

Multiplying value 1 of x with all values of y 

How it is done using array

 


Accepted Solutions
Solution
‎03-31-2017 12:06 AM
Super User
Posts: 5,505

Re: Arrays

Arrays are not part of the solution.  Arrays always refer to a single observation at a time. 

 

Here is a way to get what you are asking for:

 

data want;

set have;

if _n_=1 then first_x = x;

retain first_x;

z = first_x * y;

drop first_x;

run;

View solution in original post


All Replies
Super User
Posts: 19,805

Re: Arrays

[ Edited ]

That wouldn't use an array at all. Arrays are short cut references to variables and work only on a single row.

A SAS data step loops through all rows implicitly.

 

data want_mult;
set have;

Z = x * y;

run;

 

 

EDIT: I misunderstood your question so this answer is incorrect, but I'm leaving it rather than deleting since it's already out there. 

Solution
‎03-31-2017 12:06 AM
Super User
Posts: 5,505

Re: Arrays

Arrays are not part of the solution.  Arrays always refer to a single observation at a time. 

 

Here is a way to get what you are asking for:

 

data want;

set have;

if _n_=1 then first_x = x;

retain first_x;

z = first_x * y;

drop first_x;

run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 146 views
  • 2 likes
  • 3 in conversation