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

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!

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