Hi all, I'm in a situation where I have to write many "case when" statements to create each of the many new variables in proc sql, while those "case when" statements are of a highly recognized pattern: when the variable starts with A then "A000", when it starts with B then "B000", etc. and it goes all the way to "Z000". I would have to write 26 "case when" statements to create one new variable. I think there must be a way to simplify and shorten the codes. Here's my original codes: proc sql;
select var1, var2
, case when substr(upper(var1),1,1) = 'A' then 'A000'
when substr(upper(var1),1,1) = 'B' then 'B000'
when substr(upper(var1),1,1) = 'C' then 'C000'
when substr(upper(var1),1,1) = 'D' then 'D000'
...
...
...
when substr(upper(var1),1,1) = 'Z' then 'Z000'
end as var1_new
from table;
quit; Hope there's a way to save me from this exhausting coding. Any help would be very much appreciated!
... View more