BookmarkSubscribeRSS Feed
EC27556
Quartz | Level 8

Hi, I am looking to perform a look-up type exercise but am unsure of how to carry it out.

 

A simplified version of my dataset is this:

 

  Date1         Date2         Date3       Date
11/01/2020 11/05/2020 11/30/2020 Date1
12/01/2020 08/30/2020 06/14/2020 Date3
.
.
.

What I want to do is create a new variable, say "ActualDate", that looks up the value of the variable "Date" and returns the value of the variable of that name.

 

So for the first row in the table above I would like ActualDate to equal "11/01/2020" and for the second row I would like it to equal "06/14/2020"

 

Is this possible and, if so, does anyone know what code is required? Thanks.

3 REPLIES 3
PhilC
Rhodochrosite | Level 12

Could your simplified dataset be structured like so?  :

  Date1         Date2         Date3       Date
11/01/2020   11/05/2020     11/30/2020      1
12/01/2020   08/30/2020     06/14/2020      3
.
.
.

Then this becomes a solution easily solved with an array, where date, as numeric, is the array index to the date_ array. 

array date_[3] date1-date3;
ActualDate=date_[date];

 

EC27556
Quartz | Level 8

Great, thank you! I would be able to get just the numbers in the "Date" column so this should work. Would you be able to write your solution in a generalised form though as I am having some trouble interpreting it (and therefore adjusting for my actual dataset!) I.e say Date1 was actually called X1, Date2 was X2 and Date3 was X3. Then say the "Date" variable was "Y" and "ActualDate" was "Z". How would your solution look in this case?

 

Many thanks for your help.

Tom
Super User Tom
Super User

If you just want the formatted value of the variable (that is string) then use the VVALUEX() function.

data want;
  set have;
  want_string = vvaluex(date);
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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