The following is a little code to help explain my problem:
LENGTH S $10 A B C $2;
When C takes on the value 'A' then I want S to take on the value of '01' (The value of the variable A). When C takes on the value 'B' then I want S to take on the value of '02' (The value of the variable B).
Here's one approach. You need to use formats to provide the decodes for A and B, and then apply that format to whatever value C takes on. In the attached sample code, provided with no guarantees, I've been very loose with the issues of case, variable types and variable lengths, but hopefully this will be enough to point you in the right direction.
value $ myfmts
length s $10;
put "First example: " s=;
put "Second example: " s=;
If you have a statement such as S=C, then you will not get the desired results (I don't think so, anyway.) Maybe this alternate program will help explain it. Consider this scenario. I have some data with home emails, work emails and and a variable that contains the person's actual email that they said they wanted to be the one used.
I want a new variable (SendTo) created in the data that contains either WORK or HOME e-mail as the value of the SendTo column.
So, first, let's say that the data looks like this. And the variables are Name, Home, Work, and Use
"Anne", "email@example.com", "firstname.lastname@example.org", "Home"
"Bob", "Bob@bb.com", "Bob@rr.com", "Work"
"Chet", "Chet@cc.com", "Chet@tt.com", "Work"
"Diane", "Diane@dd.com", "Diane@tt.com", "Home"
"Eudora", "Eudora@ee.com", "Eudora@rr.com", "Home"
"Fiona", "Fiona@ff.com", "Fiona@xx.com", "Other"
and that the data lives in a file called email_info.txt in my c:\temp directory. Next, I need to read the data and make the SendTo column:
LENGTH SendTo Home Work $20 Use $5;
infile 'c:\temp\email_info.txt' dsd;
input name $ Home $ Work $ Use $ ;
So the key statement is where the SendTo variable will take on the value of whereever the Use variable points to (either Work or Home).
Then if you do a proc print on the final data set (after running the above program), you will see:
Obs name Home Work Use SendTo
1 Anne email@example.com firstname.lastname@example.org Home email@example.com
2 Bob Bob@bb.com Bob@rr.com Work Bob@rr.com
3 Chet Chet@cc.com Chet@tt.com Work Chet@tt.com
4 Diane Diane@dd.com Diane@tt.com Home Diane@dd.com
5 Eudora Eudora@ee.com Eudora@rr.com Home Eudora@ee.com
6 Fiona Fiona@ff.com Fiona@xx.com Other
In this example, vvaluex acted as a lookup within one row. For Anne's row, the value of Use was Home.
So when SAS was on Anne's row of data, imagine that this is what happened:[pre]
SendTo=vvaluex(Use) --> SendTo=vvaluex(Home) --> SendTofirstname.lastname@example.org[/pre]
On the other hand, for Chet's row, the resolution for the function would be:[pre]
SendTo=vvaluex(Use) --> SendTo=vvaluex(Work) --> SendTo=Chet@tt.com[/pre]
It's hard to figure out exactly what the original person needed to do...since the data was made up data. But, if I had used SendTo = Use as the assignment statement in my code, then I would NOT have gotten the actual email address for the value of SendTo, I would just have gotten either Home or Work (or whatever the value of Use was).
There are a lot of ways to do lookups with SAS, including, but not limited to, Proc Format, IF statements, Merge, Join -- most of these involve a fixed list. On the other hand, the VVALUEX function allows you to do a lookup on the same row. Tech Support may be your best bet for solving these kinds of problems because each method has pros and cons that can change depending on the kind of data you have, the kind of lookup you need to do and the size of the tables involved or the the kind of variables involved.