Does SAS have a built-in function or a triple operator?

I am trying to concatenate a long string in SAS, and it would be useful to have a built-in if or trernary function so that I can insert IF expressions into the concatenation. I cannot find mention of this in the docs. In the DATA step, I would like to do something like:

myString = "some words " || dead == 1 ? 't' : 'f' || " some more words" ....

Basically, I'm trying to create seeds for a demo Rails application so that I can quickly dump some SAS data into a SQLite database.

Is there any built-in if in SAS?

+8
sas
source share
2 answers

The ifc function (character version, ifn numeric) is the built-in if function in SAS. This in SAS will be:

 myString = cat("some words ",ifc(dead=1,'t','f')," some more words"); 

(functions of the cat family, such as cat, catx, etc., are more often used than the || operator in SAS).

+15
source share

A more traditional SAS way to generate text based on the value of a variable is to define the format.

 proc format ; value dead 1='dead' 0='alive' other='unknown'; run; ... myString = catx(' ','some words',put(dead,dead.),'some more words'); 
0
source share

All Articles