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
correspondence
Re: correspondence
If the list of names and codes is small you can simply use a set of if statements:
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:
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".
if NAME="Josh" then
CODE=1;
elseif NAME="Show87" then
CODE=2;
elseif NAME=
etc...CODE=1;
elseif NAME="Show87" then
CODE=2;
elseif NAME=
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.htmlif loadcase(LOOKUP_DICT, LOOKUP_NAME) then
CODE = LOOKUP_CODE;
endif
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
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:
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;