DATA Step, Macro, Functions and more


Super Contributor
Posts: 1,041


Hello ,


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




INP         102

INP         103


INP         105

INP         106


INP        109



Super User
Posts: 6,765

Re: Blanks

Posted in reply to robertrao

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;

Frequent Contributor
Posts: 93

Re: Blanks

Posted in reply to robertrao

Out of curiosity, which one is more accurate?  I assume that the second option would be more accurate, but what are you finding in your data?

Super User
Super User
Posts: 9,599

Re: Blanks

Posted in reply to robertrao

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?

Super User
Posts: 10,238

Re: Blanks

Posted in reply to robertrao

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.

Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 4 replies
  • 1 like
  • 5 in conversation