BookmarkSubscribeRSS Feed
timj22
Calcite | Level 5

Hi everyone,

I have a dataset where one column is filled with column headers, and I was to return the value from that header back to that row.

For example

 

SAS DAta Set:

 

Name   Lookup     1     2     3     Return

John        2            a     d      v        d       

Tim          2            a     c      v        c

Kat          3             c     d      v        v

Jim          1             c     c      d        c

So as you can see from above

if lookup = 2 then return the value from column 2.

Now my dataset is much larger so I cant just use if/then to bring back every combination..

Any ideas?

 

Cheers

2 REPLIES 2
Astounding
PROC Star

This should be a straightforward application of arrays:

 

data want;

set have;

array vars {3} v1 v2 v3;

return = vars{lookup};

run;

 

Note that I illustrated using variable names of V1, V2, and V3, since 1, 2, and 3 are not valid variable names in SAS.  Also note that you may need to assign a length to RETURN before assigning a value.  If the variables in the array have different lengths, you may need to ensure that RETURN is assigned a long enough length to hold the longest value it might encounter.

Reeza
Super User

Look at the VVALUE/VVALUEX function.

 

 

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
  • 931 views
  • 0 likes
  • 3 in conversation