Automatically filling up NAME from CODE

Discussions about CSEntry
Post Reply
Socio
Posts: 48
Joined: May 1st, 2017, 4:47 am

Automatically filling up NAME from CODE

Post by Socio »

Hi everyone

I would like to add state code and state name. It should be if I select state CODE in Q1, correspondent state NAME must fill up automatically in Q2.
eg.
Q1: CODE
Q2: NAME
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Automatically filling up NAME from CODE

Post by josh »

If the number of states is small you can just use a series of if else statements in the preproc of the name variable:
PROC Q2_NAME
preproc
if Q1_CODE = 1 then
    Q2_NAME =
"Alabama";
elseif Q1_CODE = 2 then
    Q2_NAME =
"Alaska";
elseif Q1_CODE = 3 then
    Q2_NAME =
"Arizona";
endif;
However if you have a lot of states then it is better to create a lookup file. Create an Excel spreadsheet with the codes in one column and the names in the other and then use the Excel to CSPro tool to convert the spreadsheet to a CSPro dictionary and data file. Add the dictionary to your application. Then in your logic you can use loadcase to get the name from the code:
PROC Q2_NAME
preproc

STATE_LOOKUP_CODE = Q1_CODE;
if loadcase(STATE_LOOKUP_DICT, STATE_LOOKUP_CODE) = 1 then
    Q2_NAME = STATE_LOOKUP_NAME;
else
    
errmsg("Invalid state code");
    
reenter;
endif;
There is a video here that talks more about lookup files: https://www.census.gov/population/inter ... pro13.html
Post Reply