Page 1 of 2

Dictionary

Posted: June 2nd, 2022, 6:01 am
by VirtuesArios
Hi I am new here, just wanna ask if how could I loop thru the dictionary so I could display the respondent's name
CS Pro.jpg
CS Pro.jpg (31.53 KiB) Viewed 11956 times

Re: Dictionary

Posted: June 2nd, 2022, 8:51 am
by aaronw
We refer to this as a dynamic value set. You can loop through a dictionary and create a dynamic value set like this:
preproc

    valueset
vs;
    forcase STAFF_DICT do
       
vs.add(strip(STAFF_NAME), STAFF_CODE);
    enddo;
   
    setvalueset(SELECT_STAFF_NAME, vs);
Check out this blog too. It goes into more depth: https://www.csprousers.org/posts/2019-0 ... bject.html

Re: Dictionary

Posted: June 13th, 2022, 12:03 am
by VirtuesArios
Thanks aaronw, I had other question with regard to the setvalueset, it has an error on SELECT_STAFF_NAME is not a declared variable or is a misspelled dictionary entry.

Code: Select all

 setvalueset(SELECT_STAFF_NAME, vs);  

Re: Dictionary

Posted: June 13th, 2022, 12:36 am
by sherrell
SELECT_STAFF_NAME is the name of the variable you're trying to build up. So, in your case you might have named the variable RESPONDENT_NAME.

sherrell

Re: Dictionary

Posted: June 13th, 2022, 1:58 am
by VirtuesArios
sherrell wrote: June 13th, 2022, 12:36 am SELECT_STAFF_NAME is the name of the variable you're trying to build up. So, in your case you might have named the variable RESPONDENT_NAME.

sherrell
Hi sherrell thanks for the reply, the name of the variable or column which I'm trying to build/display are STAFF_NAME which is on the STAFF_DICT but I have a new error

Code: Select all

preproc

valueset vs;
	forcase STAFF_DICT do
		vs.add(strip(STAFF_NAME), STAFF_CODE);
	enddo;	
		
setvalueset (STAFF_NAME, vs); 
setvalueset (STAFF_NAME, vs); --- error---- "The type of the value set (numeric/alpha) must match the type of the variable"

Re: Dictionary

Posted: June 13th, 2022, 1:23 pm
by sherrell
It sounds like you're creating a value set that contains strings and trying to assign it to a numeric field, or vice versa. If you could zip up your program it would make it easier. If you'd prefer not to share it here, please email it to us at cspro@lists.census.gov

Thanks,
Sherrell

Re: Dictionary

Posted: June 24th, 2022, 9:39 am
by VirtuesArios
Thanks Sherrell, sorry it took to long for me to reply I was busy for the past few days anyway, I've attached the program I was working on hope you could give me some pointers on how this Menu/Login works, thanks in advance I really appreciate it.

Re: Dictionary

Posted: June 24th, 2022, 11:16 am
by sherrell
You're almost there. While you could assign the contents of your constructed valueset back to the variable you used in its creation, as I mentioned earlier, you've got conflicting variable types. You're creating a valueset using the numeric variable STAFF_CODE as the value; however STAFF_NAME wants a string not a numeric. I believe what you want to do is assign the constructed valueset to choose_household variable, whose logic you're within.

Here's the updated code block:

Code: Select all

	
PROC CHOOSE_HOUSEHOLD
preproc	
	valueset vs;
	
	forcase STAFF_DICT do
		vs.add(strip(STAFF_NAME), STAFF_CODE);
	enddo;
	
	// setvalueset (STAFF_NAME, vs);   >> incorrect
	setvalueset ($, vs);		  // correct
	
This worked for me. Although there's no way to reach the PROC CHOOSE_HOUSEHOLDS the way the pgm is coded, so I had to allow that to happen to test this out.

Also note the logic above adds everyone, supervisors and interviewers. So if you didn't want supervisors for example, you'd want to filter them out. For example,

Code: Select all

forcase STAFF_DICT where STAFF_ROLE = 2 do
Sherrell

Re: Dictionary

Posted: June 30th, 2022, 12:23 am
by VirtuesArios
Thanks sherrell for the this it was very helpful I was able to run things and see all the names/interviewers of the list, another question is there a way that I could list only the names/interviewers that corresponds to the login supervisor with the use of TEAM_ASSIGNMENTS

Re: Dictionary

Posted: June 30th, 2022, 4:47 pm
by sherrell
I see there's a variable TEAM_ASSIGNMENTS in the staff dictionary, but since it's only 1 digit and has no value set, I don't know how you're using it/what you're using it for.

If you track what team # each person (whether supervisor or interviewer) belongs to, then when a given supervisor is logged in you could do a series of locate or find calls to load everyone on the supervisor's team, and create the list as you load each case.

https://www.csprousers.org/help/CSPro/l ... ction.html
https://www.csprousers.org/help/CSPro/f ... ction.html

Sherrell