Function to return the count of categories

Discussions about editing and cleaning data
Post Reply
YFT_CBSD
Posts: 52
Joined: January 3rd, 2023, 12:36 am

Function to return the count of categories

Post by YFT_CBSD »

Hi, what function can i use to return the total count of categories?(highlighted in yellow mark)

for example data item of City. (please check the picture).
Tried using the STAT function but i only want to return the count of categories.

btw this is a batch editing tool
Thanks in advance.
Attachments
city.png
city.png (10.6 KiB) Viewed 5081 times
Gregory Martin
Posts: 1846
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Function to return the count of categories

Post by Gregory Martin »

One option is to use a HashMap to keep track of your values, and then count the number of keys in the HashMap, which will tell you how many unique values were added. For example:
HashMap relationshipHashMap;

PROC PROGRAM_FF

    errmsg("There were %d relationship codes", relationshipHashMap.length());  

PROC RELATIONSHIP

    relationshipHashMap(RELATIONSHIP) = true;
YFT_CBSD
Posts: 52
Joined: January 3rd, 2023, 12:36 am

Re: Function to return the count of categories

Post by YFT_CBSD »

Thanks, how can i do it in a tabulation application, adding a new data item as a categories counter?
Gregory Martin
Posts: 1846
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Function to return the count of categories

Post by Gregory Martin »

You can use the working storage dictionary to create an item, e.g., Categories. Then, in post-calc logic, you can set the value of that cell to relationshipHashMap.length().

Here is some reading that may help you do this:

https://www.csprousers.org/help/CSPro/t ... logic.html

https://www.csprousers.org/help/CSPro/p ... cells.html
Post Reply