There's no particular reason that shouldn't work as you coded it in theory - see this example:
data have;
dsae='AE: (1) hypertension 16-NOV-2017';
dsde='something else';
if DSAE ne '' then reason = strip(DSDE) || ': ' || scan(DSAE ,3,' ');
else if DSAE = '' then reason = strip(DSDE);
run;
Now, you may run into issues with lengths, which could be keeping you from getting your correct result.
I also would note that the `else if` there isn't really necessary, it seems like it should just be `else`. While those two conditions should be the full set of possibilities, you run into issues where you could have a mistake that makes both of them false. (I'm also not sure what happens if that is processed in SQL for example, where '' and ' ' are different, and NULL is something yet different.)
I would code it this way:
data have;
length reason $50;
dsae='AE: (1) hypertension 16-NOV-2017';
dsde='something else';
reason = catx(': ',DSDE,scan(DSAE ,3,' '));
run;
But mostly that's just stylistic differences. The ELSE is not necessary here as CATX will not add the delimiter if the argument is blank.
If the above doesn't work for you, you'll need to give some example data that reproduces your particular issue, and let us know if there's anything complicated here like a non-SAS data source on the SET statement.
First try adding a LENGTH statement that's sufficiently long, though, I think that could well be part of your issue.
... View more