Hello dear users I have a problem:
There is a base (SPSS) which stores the results of a survey of 3,000 households of which 800 will be selected profiles and for them to be interviewed, as I read some of the answers of the respondents from the old database (where 3000 profiles) and display them in a new entry?
For example there is the question:
Over the past 10 days who do not be sick in your household? If the answer is yes it should appear the names of the members of the household in the response categories (value set)
Now I have only one option to add a 800 response options (value set) and change them depending on the household id.
Maybe there is some do not be another option? How to do it by faster?
(Translated by Google translator)
How to read data from another database?
-
R.is
- Posts: 14
- Joined: February 7th, 2015, 4:54 am
- Location: Tajikistan, Dushanbe
-
josh
- Posts: 2403
- Joined: May 5th, 2014, 12:49 pm
- Location: Washington DC
Re: How to read data from another database?
If understand your question you want to load data from a previous survey into your current data entry application. Usually this is done with a lookup file. You create an external dictionary and use the command loadcase() to load data from it. You can then use the command setvalueset() to create the valueset based on the data in the lookup file. There is a lookup file example in the CSPro examples directory that may be helpful.
-
R.is
- Posts: 14
- Joined: February 7th, 2015, 4:54 am
- Location: Tajikistan, Dushanbe
Re: How to read data from another database?
Hello, thank you for your reply but I have and nothing happened, I looked in the examples it is really difficult and I did not understand because I do not have long started to learn cspro can somebody help me figure it out
Here's an example I have two dictionary dict1 and dict2 in dict1 have 3 questions gender, age and name
and there are 4 or questions dict2 sex, age, name, and date of interview
how can I get the sex, age, name of dict1 and written dict2
write what I need to do?
translated into Google translator
Here's an example I have two dictionary dict1 and dict2 in dict1 have 3 questions gender, age and name
and there are 4 or questions dict2 sex, age, name, and date of interview
how can I get the sex, age, name of dict1 and written dict2
write what I need to do?
translated into Google translator
-
josh
- Posts: 2403
- Joined: May 5th, 2014, 12:49 pm
- Location: Washington DC
Re: How to read data from another database?
Create a data entry application using dict2 as the main dictionary. Then add dict1 as an external dictionary. In your application you call loadcase on dict2 to load the name, age and sex. Loadcase looks up a case in an external dictionary (dict2 in your case). You need to tell it which case to find by passing it the appropriate id items. For example if the id items in dict2 are province, district, village, and householdnumber then you could call loadcase like:
In your case you probably have the same id items in dict1 and dict2 and want to use the id items in dict1 to load the corresponding case in dict2. In that case you would do:
It is important that both dictionaries have the same lengths for the id items and also the same settings for zero fill otherwise loadcase will not find the correct match.
Once your loadcase has worked you can simply copy from dict2 to dict2 by assigning the variables:
if loadcase(DICT2, 10, 12, 14, 101) <> 1 then
errmsg("Failed to find case");
endif;
This will look in the data file associated with dict2 and search for a case where province=10, district=12, village=14 and householdnumber=101. If it finds one it returns one, otherwise it returns zero.errmsg("Failed to find case");
endif;
In your case you probably have the same id items in dict1 and dict2 and want to use the id items in dict1 to load the corresponding case in dict2. In that case you would do:
if loadcase(DICT2, DICT1.PROVINCE, DICT1.DISTRICT, DICT1.VILLAGE, DICT1.HOUSEHOLDNUMBER) <> 1 then
errmsg("Failed to find case");
endif;
Note the use of "DICT1." to disambiguate between DICT1 and DICT2 in case the two dictionaries both have the same names for the id items. Often to avoid having to do this people will name the fields diffrently in the two dictionaries. For example in dict1 you could have D1_PROVINCE, D1_DISTRICT and in dict2 you could have D2_PROVINCE, D2_DISTRICT. Either way works. Whatever you find easier.errmsg("Failed to find case");
endif;
It is important that both dictionaries have the same lengths for the id items and also the same settings for zero fill otherwise loadcase will not find the correct match.
Once your loadcase has worked you can simply copy from dict2 to dict2 by assigning the variables:
if loadcase(DICT2, DICT1.PROVINCE, DICT1.DISTRICT, DICT1.VILLAGE, DICT1.HOUSEHOLDNUMBER) <> 1 then
errmsg("Failed to find case");
else
DICT1.NAME = DICT2.NAME;
DICT1.AGE = DICT2.AGE;
DICT1.SEX = DICT2.SEX;
endif;
errmsg("Failed to find case");
else
DICT1.NAME = DICT2.NAME;
DICT1.AGE = DICT2.AGE;
DICT1.SEX = DICT2.SEX;
endif;
-
R.is
- Posts: 14
- Joined: February 7th, 2015, 4:54 am
- Location: Tajikistan, Dushanbe
Re: How to read data from another database?
please see the right I'm doing everything that goes wrong I have nothing
PROC D2_ID
if loadcase (D1_DICT, D1_DICT.SEX, D1_DICT.AGE, D1_DICT.NAME) <> 1 THEN
ERRMSG ("Failed to find case");
ELSE
D1_DICT.SEX = D2_DICT.SEX;
D1_DICT.AGE = D2_DICT.AGE;
D1_DICT.NAME = D2_DICT.NAME;
ENDIF;
when I run it says Failed to find an hour and everything
in the old database contains 5 records
PROC D2_ID
if loadcase (D1_DICT, D1_DICT.SEX, D1_DICT.AGE, D1_DICT.NAME) <> 1 THEN
ERRMSG ("Failed to find case");
ELSE
D1_DICT.SEX = D2_DICT.SEX;
D1_DICT.AGE = D2_DICT.AGE;
D1_DICT.NAME = D2_DICT.NAME;
ENDIF;
when I run it says Failed to find an hour and everything
in the old database contains 5 records
-
josh
- Posts: 2403
- Joined: May 5th, 2014, 12:49 pm
- Location: Washington DC
Re: How to read data from another database?
Your code is trying to load a case from D1_DICT using the variables SEX, AGE and NAME from D1_DICT. Those will be blank since no case has been loaded for D1_DICT. If you notice in my code I'm using the variables from dict1 as the arguments to loadcase. You need to use the values of the id items from one dictionary to find the corresponding case in the other dictionary. So you want to use the variables from D1_DICT to lookup the value in D2_DICT:
PROC D2_ID
if loadcase (D2_DICT, D1_DICT.SEX, D1_DICT.AGE, D1_DICT.NAME) <> 1 THEN
ERRMSG ("Failed to find case");
else
D1_DICT.SEX = D2_DICT.SEX;
D1_DICT.AGE = D2_DICT.AGE;
D1_DICT.NAME = D2_DICT.NAME;
endif
if loadcase (D2_DICT, D1_DICT.SEX, D1_DICT.AGE, D1_DICT.NAME) <> 1 THEN
ERRMSG ("Failed to find case");
else
D1_DICT.SEX = D2_DICT.SEX;
D1_DICT.AGE = D2_DICT.AGE;
D1_DICT.NAME = D2_DICT.NAME;
endif
-
R.is
- Posts: 14
- Joined: February 7th, 2015, 4:54 am
- Location: Tajikistan, Dushanbe
Re: How to read data from another database?
if I change D1_DICT on D2_DICT it I did not compile and gives this error
ERROR: One-level external dictionary name expected near line 1 in D2_ID procedure
ERROR: One-level external dictionary name expected near line 1 in D2_ID procedure
-
josh
- Posts: 2403
- Joined: May 5th, 2014, 12:49 pm
- Location: Washington DC
Re: How to read data from another database?
That means one of three thrings:
1) You have not added D2_DICT to your application as an external dictionary.
2) You have added the dictionary to your application but D2_DICT is not the correct name of the dictionary.
3) D2_DICT is a two-level dictionary. Two level dictionaries cannot be used as lookup files.
1) You have not added D2_DICT to your application as an external dictionary.
2) You have added the dictionary to your application but D2_DICT is not the correct name of the dictionary.
3) D2_DICT is a two-level dictionary. Two level dictionaries cannot be used as lookup files.
-
R.is
- Posts: 14
- Joined: February 7th, 2015, 4:54 am
- Location: Tajikistan, Dushanbe
Re: How to read data from another database?
help to solve this problem can describe in detail how I do it, I just do not quite understand what you mean
-
josh
- Posts: 2403
- Joined: May 5th, 2014, 12:49 pm
- Location: Washington DC
Re: How to read data from another database?
Have you added dict2 to your application? If you have then when you click on the files tab (bottom left corner of the screen) you will see it listed in the tree underneath your application. If it is not there then you need to add the dictionary. From the files menu choose "Add Files".
If that is not the problem then double check that D2_DICT is the correct name of the dictionary. You can see the name in the dictionary editor. Make sure you are using the name and not the label.
Does your dictionary have more than one level? If it does then this won't work. You can only use one level dictionaries.
If that is not the problem then double check that D2_DICT is the correct name of the dictionary. You can see the name in the dictionary editor. Make sure you are using the name and not the label.
Does your dictionary have more than one level? If it does then this won't work. You can only use one level dictionaries.