Page 1 of 1

correspondence

Posted: April 20th, 2017, 4:34 pm
by Show87
Hello


I have a list of names with corresponding codes.

I wanted to do this
If a name is selected in the variable "NAME" automatically the variable "CODE" displays are corresponding code without possibility of modification.


example

NAME CODE
Show crv01

Re: correspondence

Posted: April 20th, 2017, 8:14 pm
by josh
If the list of names and codes is small you can simply use a set of if statements:
if NAME="Josh" then
    CODE=
1;
elseif NAME="Show87" then
    CODE=
2;
elseif NAME=
etc...

If the list of names is long you can use a lookup file. Create an Excel spreadsheet with the names in one column and the codes in a second column. Add an external dictionary to your CSPro application that has a single record with the name as the id-item and the code as a variable on the record. Use the Excel2CSPro tool to convert the Excel spreadsheet to a CSPro data file. In your logic use loadcase to lookup the code from the name. If you named the external dictionary LOOKUP_DICT and the variables in the external dictionary LOOKUP_NAME and LOOKUP_CODE you would do:
LOOKUP_NAME = NAME;
if loadcase(LOOKUP_DICT, LOOKUP_NAME) then
    CODE = LOOKUP_CODE;
endif
For more information on lookup files checkout the lookup file example in the CSPro examples folder and the following tutorial: https://www.census.gov/population/inter ... pro13.html

You can make the code field protected so that it cannot be modifed. To make a field protected, right-click on the field, select "Field properties" and check the box for "Protected".

Re: correspondence

Posted: April 22nd, 2017, 5:52 pm
by Saint
You can add a value set to the CODE variable for the NAMES and CORRESPONDING codes. You have to define CODE as alphanumeric, and the value set should look like:
VALUE LABEL FROM
101 JOSH
102 GREG

Then you can protect the CODE FIELD and add the following logic on the CODE variable:

Code: Select all

PROC CODE
PREPROC
CODE = getlabel(CODE_VS1, NAME);

POSTPROC
if length(strip(CODE)) = 0 then
  errmsg("NAME given is not valid");
  reenter NAME;
endif;