Reputation: 2999
I'm trying to concatenate a long string in SAS and it would be helpful to have an inline if function or ternary operator so that I can nest IF statements in the concatenation. I can't find mention of this in the docs. In a DATA step, I'd like to do something like:
myString = "some words " || dead == 1 ? 't' : 'f' || " some more words" ....
Basically, I'm trying to generate some seeds for demonstration Rails app, so that I can dump some SAS data into a SQLite database quickly.
Is there any sort of inline if in SAS?
Upvotes: 8
Views: 3365
Reputation: 51611
A more traditional SAS way to generate text based on the value of a variable is to define a format.
proc format ;
value dead 1='dead' 0='alive' other='unknown';
run;
...
myString = catx(' ','some words',put(dead,dead.),'some more words');
Upvotes: 1
Reputation: 63424
The ifc
function (character version, ifn
numeric) is the inline if
function in SAS. That in SAS would be:
myString = cat("some words ",ifc(dead=1,'t','f')," some more words");
(cat family functions like cat,catx,etc. are more commonly used than the || operator in SAS).
Upvotes: 18