stallingOne
stallingOne

Reputation: 4006

How to write a condition inside a cats() string-concatenation in SAS

Is it possible to write a condition inside a cats() function?

Something like this:

data ...
   ...
   line2=cats('xxxx',if (severity=.) then 'missing' else severity,'yyyyy');
   ...

I would like to do this in order to write a json file. Because severity is a numeric variable, when it's missing it's a . and that create invalid json files. I'm searching for a way to replace these dots with a string in the json like e.g. 'missing' in my example.

EDIT: Forgot to say I'm in a data step here

Upvotes: 0

Views: 170

Answers (1)

Tom
Tom

Reputation: 51611

Why not just use the IFC() function?

ifc(severity=.,'missing',put(severity,best12.))

Of define a format.

proc format ;
  value severity .='missing' other=[best12.];
run;
...
line2=cats('xxxx',put(severity,severity.),'yyyyy')

Upvotes: 3

Related Questions