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
Automatically filling up NAME from CODE
Re: Automatically filling up NAME from CODE
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: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;
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.htmlpreproc
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;