You could easily add it:
%let age4=%str(length groupCat1 $ 5; if age<20 then groupCat1 ='<20'; else if age<35 then groupCat1='20-34'; else if age<45 then groupCat1='35-44'; else groupCat1='45+'; );
As you mentioned, this is a practice exercise. It would be rare for %str to be used this way in practice just as a matter of style. But it is perfectly valid for learning purposes. If this logic were re-usable code that would apply to many DATA steps, you might actually create a macro instead of a macro variable:
%macro age4;
length groupCat1 $ 5;
if age<20 then groupCat1 ='<20'; else if age<35 then groupCat1='20-34'; else if age<45 then groupCat1='35-44'; else groupCat1='45+'; %mend age4;
It's re-usable, since macros can be stored permanently. It's easier to read. And calling the macro is just as easy as using a macro variable:
%age4
... View more