4

I was reading the SAS code for calculating NBBO, and I came across the following code:

array nexb nexb:; array nexo nexo:; array sexb sexb:; array sexo sexo:;

I was wondering what does the statement array nexb nexb:; do here?

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
Jinhua Wang
  • 1,679
  • 1
  • 17
  • 44
  • Here's a link to the other various ways of listing variables using shortcuts: http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtqzizp1n39.htm – Reeza May 16 '17 at 22:00
  • 1
    Just noticed the Wharton copyright on the code above, please make sure it's ok to post this macro publicly. – Reeza May 16 '17 at 22:07
  • @Reeza I think it is fine? Because it is part of a Wharton tutorial teaching people how to use their services. Also I sourced the material and it's authors. In any case if Wharton sends me an email asking me to take it down I will follow their instructions. – Jinhua Wang May 16 '17 at 22:16
  • That's not how it works. If you're unsure inquire, since the tutorials appear behind a secure log in I suspect they're not freely available. – Reeza May 17 '17 at 00:20
  • Ok I deleted the code. – Jinhua Wang May 17 '17 at 01:30

1 Answers1

5

Two things:

nexb: is a variable list with a wildcard. It expands to the list of all variables on the PDV at that point in the data step that begin with nexb. So the same as nexb1-nexb17 more than likely (without knowing what's in the datasets in the set statement though). It's identical, and just used to make it easier to change that 17 sometime later without having to do so twice.

array nexb nexb: creates an array, which is simply an organized variable list that allows you to say nexb[1] instead of nexb1, which is really more useful since [1] can be [i] or some other variable, while nexb1 cannot. So it allows you to go through a list of variables one at a time and use them or change them. The array does not exist in the dataset itself and is not persistent, it's just a shorthand way to refer to the variables.

Joe
  • 62,789
  • 6
  • 49
  • 67
  • Does "array nexb nexb:" declares two arrays? – Jinhua Wang May 16 '17 at 22:04
  • No. `array nexb nexb:` is declaring array `nexb` comprising of variables `nexb:`. – Joe May 16 '17 at 22:06
  • And `array nexb;` would not work. You need to supply it either a list of variables or a count. – Joe May 16 '17 at 22:06
  • Hi Joe, I am reading the source code again: https://wrds-web.wharton.upenn.edu/wrds/research/applications/sas_files/nbbo.sas I found it pretty weird. Why does the author defines variable nexb1-17 and then add it to an array? Can't he just directly create an array? – Jinhua Wang Jun 17 '17 at 01:39