Small Language Additions: Count, Seek, Sort


In CSPro 4.1.002 there are three small language changes and additions that may make writing code easier. First, the change:

numeric numChildren = count(POP_REC where RELATIONSHIP = 3); // old
numeric numChildren = count(RELATIONSHIP = 3); // new

In the past, when using the count function it was necessary to specify what record or group you wanted to search through (in the above case, POP_REC). Now you can write the code without specifying this clause.

The seek function, new to CSPro 4.1, searches a record for the first instance of something being true. Now, in CSPro 4.1.002, you can search for the nth occurrence of the conditional statement. For example, this loop will continue until there are no longer two spouses in a household:

do while seek(RELATIONSHIP = 2,@2)

   
// change the second spouse's relationship

enddo;

Finally, the sort function has long been a useful feature of the CSPro language, but now you can use it with a where statement. For example, a common request is to have a roster sorted based on relationships. This example sorts a roster by relationship, and then sorts the children in order by descending age:

sort(POP_REC_EDT using RELATIONSHIP);
sort(POP_REC_EDT using -AGE where RELATIONSHIP = 3);