Focal Point
[SOLVED] Alphabetic letter counts

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/579105184

July 06, 2010, 10:15 AM
ramakrk
[SOLVED] Alphabetic letter counts
Hi
COMPUTE alphanames/A40 = SUBSTR(40, Lastname,1,1,40, 'A40');
This substr picks the first letter in the lastname field, if this is equal to letter 'A' then count all 'A's of lastnames. Like , i need to compare all alphabetic letters and gets their counts for the incoming Lastname field.
the ouput is A B C D..... Z
12 4 1 19...... 4
what is the best logic for this.
Thanks for the help,
Ram

This message has been edited. Last edited by: Kerry,


WebFOCUS 762
Windows
To be decided(All formats)
July 06, 2010, 10:32 AM
Dave
You could, in stead of a COMPUTE, use a DEFINE with the same formula.

DEFINE FILE yourfile
alphanames/A40 = SUBSTR(40, Lastname,1,1,40, 'A40');
END

TABLE FILE yourfile
    SUM CNT.DST.Lastname
    BY alphanames

...output whatever needed...


(unchecked code)

Use a CNT or CNT.DST, depends on what you need.


_____________________
WF: 8.0.0.9 > going 8.2.0.5
July 06, 2010, 10:40 AM
ramakrk
Dave,
Thanks for the solution , but what i need is a logic, which gives how many(count) lastnames starts with letter A and how many with(count) lastnames starts with letter B etc...upto Z aplhabetical letters .
Thanks for the help,
ram


WebFOCUS 762
Windows
To be decided(All formats)
July 06, 2010, 10:41 AM
Francis Mariani
How about:
SET NODATA = 0

DEFINE FILE EMPDATA
LASTNAME_1ST_CHAR/A1 = SUBSTR(15, LASTNAME, 1, 1, 1, 'A1');
END

TABLE FILE EMPDATA
SUM
CNT.LASTNAME_1ST_CHAR AS 'EMPLOYEE,COUNT'
BY LASTNAME_1ST_CHAR
ROWS
A OVER B OVER C OVER D OVER E OVER
F OVER G OVER H OVER I OVER J OVER
K OVER L OVER M OVER N OVER O OVER
P OVER Q OVER R OVER S OVER T OVER
U OVER V OVER W OVER X OVER Y OVER Z
END


The ROWS OVER syntax is to ensure all 26 letters appear in the report, you can remove this code if all letters are not required. EMPDATA is a file in the WebFOCUS sample data folder, ibisamp.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
July 06, 2010, 10:47 AM
ramakrk
Francis,
Compare lastnames with all 26 aplhabets and their corresponding counts.i.e how many lastnames starts with alphabet A and their count.Like all 26 alphabets.
A
count(LASTNAMES)
B
count(lastnames)
thanks,
ram


WebFOCUS 762
Windows
To be decided(All formats)
July 06, 2010, 10:55 AM
Francis Mariani
quote:
Compare lastnames with all 26 aplhabets and their corresponding counts.i.e how many lastnames starts with alphabet A and their count.Like all

I don't understand.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
July 06, 2010, 10:59 AM
Francis Mariani
The output of my program:
   EMPLOYEE
   COUNT
   --------
A         3
B         1
C         6
D         2
E         1
F         1
G         3
H         1
I         0
J         0
K         1
L         4
M         3
N         1
O         1
P         3
Q         0
R         2
S         3
T         0
U         0
V         1
W         4
X         0
Y         0
Z         0


If this is not what you're looking for, please show us your desired output, in between CODE tags please.

[code]
your output here
[/code]



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
July 06, 2010, 11:09 AM
ramakrk
Francis,
The ouput is correct.Does your logic
is same as this.
COMPUTE alphanames/A40 = SUBSTR(40, Lastname,1,1,40, 'A40');
If alphanames eq 'A' then count(alphanames)
If alphanames eq 'B' then count(alphanames);
If alphanames eq 'C' then count(alphanames);
If alphanames eq 'D' then count(alphanames) ;
.
.
If alphanames eq 'Z' then count(alphanames)
output is
A 20-count of lastnames starts with letter A
B 45--count of lastnames starts with letter B

.
Z 32--count of lastnames starts with letter Z

Thanks


WebFOCUS 762
Windows
To be decided(All formats)
July 06, 2010, 11:53 AM
ramakrk
francis,
Thanks for a wonderful hint. I think i got it.
Thanks for the help,
ram


WebFOCUS 762
Windows
To be decided(All formats)
July 07, 2010, 03:26 AM
Dave
Ram,

I don't get it.. My logic does -exactly- that.
I've made a sample on the CAR file.

It counts the number of cars starting with each character.

DEFINE FILE CAR
	ALPHA/A1 = SUBSTR(40, CAR, 1,1,40, 'A1');
END

TABLE FILE CAR
	SUM CNT.CAR AS 'NUMBER OF CARS STARTING WITH'
	BY ALPHA
ON TABLE PCHOLD FORMAT HTML
END


You will not get the entire alphabet. Only the character which have data.

This fixable :

DEFINE FILE CAR
	ALPHA/A1 = SUBSTR(40, CAR, 1,1,40, 'A1');
END

TABLE FILE CAR
	SUM CNT.CAR AS 'NUMBER OF CARS STARTING WITH'
	BY ALPHA
		ROWS 'A' OVER 'B' OVER 'C' OVER 'D' OVER 'E'
		OVER 'F' OVER 'G' OVER 'H' OVER 'I' OVER 'J'
		OVER 'K' OVER 'L' OVER 'M' OVER 'N' OVER 'O'
		OVER 'P' OVER 'Q' OVER 'R' OVER 'S' OVER 'T'
		OVER 'U' OVER 'V' OVER 'W' OVER 'X' OVER 'Y'
		OVER 'Z' 
ON TABLE PCHOLD FORMAT HTML
END

( working & checked example )

G'luck.


_____________________
WF: 8.0.0.9 > going 8.2.0.5
July 07, 2010, 04:31 AM
Tony A
Dave,

Take heart in that most of us knew that your response was, indeed, the solution. However, it was missing the 'A' OVER 'B' etc. has been mentioned on the Forum so many times before so, perhaps, we may have expected a quick pickup.

I guess that some of our newer members do not have the depth of knowledge (or DP background) that would give them the edge to see past the initial response(s) (is that not why they are here?). Consequently many responders may feel slighted or ignored.

Of course we could always suggest that posters remember to use the search engine (top right) but I would urge them to remember that it might need a different search to what is in their mind! This is probably one of the most common reasons for not finding what they need.

A suggestion that I would make to everyone is to signup for the digest and take the time out of their busy schedules to actually read as much as they have time for - even skim reading the content - you never know what might become useful in future. I would also suggest making a library of posted samples, giving the individual files a meaningful name. I know several "seasoned" WF Pro's that keep such a library close to hand on a memory stick.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
July 07, 2010, 06:49 AM
Dave
No harm done,
Glad I could help anyway.

It's been more a misinterpretation the question at hand.

...isn't that always the problem with our customers as well? Big Grin


_____________________
WF: 8.0.0.9 > going 8.2.0.5
July 07, 2010, 01:10 PM
ramakrk
Hi Dave
very helpful logic.I feel proud of the servise which you are giving it to the forum.
Thanks,
Rama


WebFOCUS 762
Windows
To be decided(All formats)