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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

2 REPLIES 2
Reeza
Super User

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. 

Astounding
PROC Star

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;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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