I have zip codes that i want to combine into two groups. How would i program this in SAS?
For example:
these zip codes need to be in GroupA
97003, 97004, 97005, 97006, 97007, 97008, 97009, 97010, 97013, 97014, 97015, 97019, 97022
97023, 97024, 97027, 97028, 97030, 97031, 97034, 97035, 97036, 97041, 97045, 97051, 97055
97056, 97060, 97062, 97064, 97068, 97070, 97078, 97080, 97086, 97089, 97106, 97109, 97112
97113, 97116, 97119, 97123, 97124, 97125, 97132, 97133, 97135, 97140, 97149, 97201, 97202
97203, 97204, 97205, 97206, 97209, 97210, 97211, 97212, 97213, 97214, 97215, 97216, 97217
97218, 97219, 97220, 97221, 97222, 97223, 97224, 97225, 97227, 97229, 97230, 97231, 97232
97233, 97236, 97239, 97242, 97258, 97266, 97267, 97268, 97286, 97292, 97330, 97331, 97333
97339, 97351, 97361, 97371, 97376, 97401, 97402, 97403, 97404, 97405, 97408, 97454, 97455
97477, 97478, 97482, 97520, 97525, 97701, 97702, 97703, 97707, 97708, 97709
and all other Oregon zip codes need to be in GroupB
data want;
set have;
if zip in (97003, 97004, 97005, 97006, 97007, 97008, 97009, 97010, 97013,
97014, 97015, 97019, 97022, 97023, 97024, 97027, 97028, 97030, 97031,
97034, 97035, 97036, 97041, 97045, 97051, 97055, 97056, 97060, 97062,
97064, 97068, 97070, 97078, 97080, 97086, 97089, 97106, 97109, 97112,
97113, 97116, 97119, 97123, 97124, 97125, 97132, 97133, 97135, 97140,
97149, 97201, 97202, 97203, 97204, 97205, 97206, 97209, 97210, 97211,
97212, 97213, 97214, 97215, 97216, 97217, 97218, 97219, 97220, 97221,
97222, 97223, 97224, 97225, 97227, 97229, 97230, 97231, 97232, 97233,
97236, 97239, 97242, 97258, 97266, 97267, 97268, 97286, 97292, 97330,
97331, 97333, 97339, 97351, 97361, 97371, 97376, 97401, 97402, 97403,
97404, 97405, 97408, 97454, 97455, 97477, 97478, 97482, 97520, 97525,
97701, 97702, 97703, 97707, 97708, 97709)
then group='GroupA';
else group='GroupB';
run;
data want;
set have;
if zip in (97003, 97004, 97005, 97006, 97007, 97008, 97009, 97010, 97013, 97014, 97015, 97019, 97022
97023, 97024, 97027, 97028, 97030, 97031, 97034, 97035, 97036, 97041, 97045, 97051, 97055
97056, 97060, 97062, 97064, 97068, 97070, 97078, 97080, 97086, 97089, 97106, 97109, 97112
97113, 97116, 97119, 97123, 97124, 97125, 97132, 97133, 97135, 97140, 97149, 97201, 97202
97203, 97204, 97205, 97206, 97209, 97210, 97211, 97212, 97213, 97214, 97215, 97216, 97217
97218, 97219, 97220, 97221, 97222, 97223, 97224, 97225, 97227, 97229, 97230, 97231, 97232
97233, 97236, 97239, 97242, 97258, 97266, 97267, 97268, 97286, 97292, 97330, 97331, 97333
97339, 97351, 97361, 97371, 97376, 97401, 97402, 97403, 97404, 97405, 97408, 97454, 97455
97477, 97478, 97482, 97520, 97525, 97701, 97702, 97703, 97707, 97708, 97709) then group='GroupA';
else group='GroupB';
run;
You most probably will have to put those codes in quotes, as zipcodes are usually stored as character.
If you store these codes in a dataset, you can use code to automate the selection and avoid typing literals in a data step.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.