correspondence

Discussions about CSEntry
Post Reply
Show87
Posts: 7
Joined: March 1st, 2017, 6:33 am

correspondence

Post 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
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: correspondence

Post 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".
Saint
Posts: 63
Joined: November 22nd, 2013, 4:59 am

Re: correspondence

Post 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;
Post Reply