04-27-2017 10:14 AM
Is there any preference for using "" versus " " to identify blank charecter fields?
I am trying to assign a value of 'OP' to all the ID's which are blank
so the IF statement can be either of the 2 below?
if INP_OP=" " then INP_OP='OP'; ---1 space
if INP_OP="" then INP_OP='OP'; ----no space between quotes
04-27-2017 10:28 AM
For the examples you listed, pick whichever you like. I find it easier to read the code when the blank appears.
Technically, there are other cases where it might make a difference. Within PROC SQL, these produce different results:
separated by ' '
separated by ''
I haven't tested it, but I imagine these could produce different results as well:
if in_op =: ' ' then do;
if in_op =: '' then do;
04-27-2017 10:30 AM
Tricky one. Yes, most of the time that would be fine having "" or " ", my preference would be for the "" as that shows a null string, whereas the other looks almost like your expecting to be one space. There are times where spaces are important, strip() versus trim() is one that pops to mind, and asis=on in proc report.
If you want to be fool proof then the simplest method is to use the missing() function rather than the logic, so rather than:
if variable=" " then flag="Y";
if missing(variable) then flag="Y";
Of course this is easier if you use numeric flags:
Its a bit of two of one and half a dozen of the other though much like the do you use || or the cat functions, in most scenarios cat functions are more readable, is cat(a,b) better then a||b?
04-27-2017 10:35 AM
When comparing a string literal to a character variable, "" is equivalent to " ", because a missing character variable is always filled with blanks, and the minimum length for a character variable is 1.