simple selective data analysis

3 views
Skip to first unread message

Larry

unread,
Apr 12, 2012, 10:49:40 AM4/12/12
to GoogleSemWare TSE, tse...@freelists.org
/*** jigselana.s

We have a big combined 50-year high school reunion coming up this year.
One of the products of the efforts of the reunion committee was to
produce a booklet of all the alumni and addresses where they currently
live. I thought it would be interesting to to show how many were
currently living in each state, so I wrote this little macro to do that.

The macro works using a datadef of all the state and US territories.
With this, it was easy to find and count how many alumni were in each
state. It turned out pretty well. :)

The basic macro can be altered to produce a simple frequency analysis of
any sort of data beyond just state abbreviations. All you have to do is
fill in the datadef with the words/character combinations that you are
interested in and execute the macro on the file of interest.

I also did a similar macro that produced a frequency analysis of all the
names of the 5 graduating classes coming to the reunion, just to get an
idea of common the various names were for our generation. :)

Just an extra little thing you can do on a whim with SAL. :)
oh tn ak fl ny ms fl
***/

// jigselana.s - selective analysis of data in a file

<ctrlshift x> execmacro("jigselana")

// state and US territory abbreviations
datadef states

"AL" "AK" "AZ" "AR" "CA" "CO" "CT" "DE" "DC" "FL" "GA" "HI" "ID" "IL"
"IN" "IA" "KS" "KY" "LA" "ME" "MD" "MA" "MI" "MN" "MS" "MO" "MT" "NE"
"NV" "NH" "NJ" "NM" "NY" "NC" "ND" "OH" "OK" "OR" "PA" "RI" "SC" "SD"
"TN" "TX" "UT" "VT" "VA" "WA" "WV" "WI" "WY" "AS" "GU" "MP" "PR" "VI"

end

proc main()

string fn[_maxpath_]=loaddir()+"stats.txt" // produced stat file

integer ob=getbufferid() // current file buffer id
integer tb=0 // buffer id of new stats file

string a[255]=""

// create the stats file
editthisfile(fn)
emptybuffer()
tb=getbufferid()

// read and insert datadef to stats file
insertdata(states)
unmarkblock()

// put data into globals
begfile()
// clear globals first
repeat
a=lower(getword())
delglobalvar(a)
until not down()
begfile()
// create globals
repeat
a=lower(getword())
setglobalint(a,0)
until not down()

// get the data frequency stats from the text
gotobufferid(ob)
pushposition()
begfile()
repeat
a=lower(getword())
if a<>"" and existglobalvar(a)
setglobalint(a,getglobalint(a)+1)
endif
until not wordright()
popposition()

// report the result to the stats file
gotobufferid(tb)
begfile()
repeat
a=lower(getword())
if a<>"" and existglobalvar(a)
endline()
inserttext(" : "+str(getglobalint(a)))
endif
begline()
until not down()

goto ending
ending:

begfile()
sound(9000,40)

end

Reply all
Reply to author
Forward
0 new messages