Hi Everyone,
I have the following data with Window and code1 code2... code100 variables.
For a given record, I compare the value in Window variable with the numerical part (the last 1 or 2 character) of the name of code. If they are the same the new Value variable will be equal to the value of that code.
Basically it should be like:
if window<=9 and window=last 1 character of variable (code1) then value=code1;
else if window<=9 and window=last 1 character of variable (code2) then value=code2
else if window>9 and window=last 2 character of variable (code11) then value=code11; *for 2 digit number;
...
So the value should be like:
1
.
4
.
6
.
.
6
.
Could you please help me with that?
Thank you so much.
HHC
data have;
input window code1 code2 code11;
datalines;
2 2 1 3
3 3 3 4
1 4 5 6
4 6 7 8
2 8 6 3
6 9 5 7
7 1 4 5
11 4 5 6
10 5 6 7
;run;
Why not create an ARRAY and use window as the subscript?
The more I think about it the less I like it. What is code, how did it get onto the data? Why does the precision change for variables > 9? Why does code and window not match one-one? Too many questions really.
Well,
data want;
set have;
if window <= 9 and window=input(substr(strip(reverse(put(code1,best.))),1,1),best.) then value=code1;
else if window <= 9 and window=input(substr(strip(reverse(put(code2,best.))),1,1),best.) then value=code1;
...
run;
Why not create an ARRAY and use window as the subscript?
Thank you, Data_Null,
It work perfectly.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.