Learning SAS? Welcome to the exclusive online community for all SAS learners.

How to classify Cities in Texas into four groups i.e North,South,East and West directions

Reply
New Contributor
Posts: 2

How to classify Cities in Texas into four groups i.e North,South,East and West directions

Hi,

Please see the sample data below.I need to create extra variable called Direction with the values North,South,East and West .Please help me.


STATESTATECODECOUNTYCITYPLACEXYLONGLATCAPITALPOPALTFEATYPE
48TX217Abbott4800100-0.018-0.0889397.0756831.88387N300217city
48TX189Abernathy4800160-0.08637-0.05224101.84507933.83184N28391024city
48TX441Abilene4801000-0.05708-0.0780499.74548232.44643N115930524city
48TX115Ackerly4801108-0.08588-0.07519101.71424232.52556N245854city
48TX359Adrian4801324-0.0964-0.02621102.66638535.27449N1591231city
48TX355Agua Dulce4801396-0.03187-0.1601497.91003327.78308N73738city
48TX215Alamo4801576-0.03575-0.1877298.11789226.18511N1476030city
48TX29Alamo Heights4801600-0.03972-0.130498.46727129.48288N7319244city
48TX417Albany4801648-0.05028-0.0733999.29447232.72684N1921431city
48TX367Aledo4801744-0.02555-0.0746197.60344132.69543N1726269city
48TX249Alice4801852-0.03437-0.1606498.0704627.75065N1901061city
48TX85Allen4801924-0.01171-0.0677196.66292233.09975N43554201city
48TX43Alpine4802104-0.11752-0.11085103.66541830.36072N57861364city
48TX215Alton4802212-0.03868-0.1859398.3059426.28431N438449city
48TX251Alvarado4802260-0.0199-0.0797697.21279232.40634N3288233city
48TX39Alvin48022720.008955-0.1324695.27158829.3937N2141314city
48TX375Amarillo4803000-0.08487-0.0283101.84516335.19925N1736271118city
48TX291Ames48030720.016911-0.1209294.74093530.05243N107922city


Thanks,

Chandra .

Super User
Posts: 5,255

Re: How to classify Cities in Texas into four groups i.e North,South,East and West directions

You can't rely on an official classification I guess? So you need first to define the directions in such way it can be applied to your data.

Data never sleeps
Super User
Posts: 10,474

Re: How to classify Cities in Texas into four groups i.e North,South,East and West directions

The basic approach I would think would be if the latitude is greater than some value (that you need to provide) then it is "North", less it would be "South", similar would be to use Long with larger values as "west" and smaller as "east".

But I submit that you have 2 dimensions and you want to combine the two for Northeast, Northwest, Southeast and Southwest.

Where your dividing lines are would be up to you as there should be some place to think of as the center. You could use the mean Lat and Long values as approximate (very approximate) for a rough center for the comparison values.

In a data step something like:

data want;

     set have;

     If Lat > 30 then n='North';

     else n='South';

     if long > 95 then e = 'West';

     else e='East';

     quadrant = cats(n,e);

run;

But the values used in the comparison should have some meaning. I picked some at random.

Ask a Question
Discussion stats
  • 2 replies
  • 264 views
  • 0 likes
  • 3 in conversation