CSPro 4.1.002 comes with a few new functions that may come in handy for your data processing needs. The function getusername returns the name under which the user logged onto Windows. This can be useful if you want to restrict access to a data entry program for only a few users. Imagine a control system for a data entry operation in which only supervisors have access to parts of the system. By giving the supervisors logins such as super1, super2, etc., you could restrict access as follows:
if pos("super",tolower(OPERATOR_NAME)) <> 1 then
errmsg("You must be logged in as a supervisor on this machine to access this program.");
stop(1);
endif;
OPERATOR_NUMBER = tonumber(OPERATOR_NAME[6]); // starting at position 6 will skip past "super"
The function randomin works by accepting as an argument either an in list or a value set. The function then returns a random value that falls somewhere in the listed values. It is now easy to get a random value within a non-continuous range:
You can weight certain values by repeating the occurrence of the value in the in list. For example, the following example will return three times as many 1 values as 2 values:
The function is probably most useful when used with a value set. For example, if you have a data file for a survey and you are planning on adding a question to the survey about religion, you may want to test out your edits for this variable. Your old data does not have this variable, so you would write a batch edit program and then add random religion data to a test data file, which you could pass through your edit programs:
The randomizevs function is useful for data entry applications that use the extended controls introduced in CSPro 4.1. Sometimes you may want to ask questions and randomize the order of the possible responses to avoid bias due to the item positioning. In the preproc of the relevant question, you could execute the randomizevs function to present a different order each time:
In the above example, 98 might be a "None of the above" code and 99 might be a "Do not know" code. You do not want these codes randomized with the rest, you always want them at the bottom of the value set list, so you exclude them from the randomization.