-
Notifications
You must be signed in to change notification settings - Fork 0
Create GeocodeEvictions_DC2024.sas #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
b70ad11
41f4019
2b7c436
903e149
569790a
05c07b0
83b8f7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /************************************************************************** | ||
| Program: {GeocodeEvictions_DC2024}.sas | ||
| Library: {Requests} | ||
| Project: Urban-Greater DC | ||
| Author: Rodrigo Garcia | ||
| Created: 10/21/24 | ||
| Version: SAS 9.4 | ||
| Environment: Local Windows session (desktop) | ||
| GitHub issue: Issue #87 | ||
|
|
||
| Description: Geocoding Eviction Data from OTA | ||
|
|
||
| Modifications: | ||
| **************************************************************************/ | ||
|
|
||
| %include "\\sas1\DCdata\SAS\Inc\StdLocal.sas"; | ||
|
|
||
| ** Define libraries **; | ||
| %DCData_lib( Requests ) | ||
| %DCData_lib( MAR ) | ||
|
|
||
| **'Proc import' and 'proc print' data import csv file into SAS**; | ||
| proc import datafile="\\SAS1\dcdata\Libraries\Requests\Raw\2024\FY24DetailedData(records).csv" | ||
| out=evictions | ||
| dbms=csv | ||
| replace; | ||
|
|
||
| getnames=yes; | ||
| guessingrows=max; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| run; | ||
|
|
||
| proc print data=work.evictions (obs=10); | ||
| run; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added |
||
|
|
||
| **Creates new data set with new street_address and zip_char variables **; | ||
| data evictions_addresses; | ||
| Set work.evictions (rename=(CASE__=Case_num)); | ||
| street_address = catx( " ", street_number, street, type, quadrant ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proc Import doesn't handle column names like "CASE #" ver well, so I used |
||
|
|
||
|
|
||
| if not( missing( zip ) ) then zip_char = put( zip, z5.0 ); | ||
| if UPCASE( disposition )='CANCELLED' then disposition= 'CANCELED'; | ||
|
|
||
| informat _all_ ; | ||
| format _all_ ; | ||
| format EVICTION_DATE mmddyy10.; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proc Import add lots of unneeded formats and informats. I use these first two statements to clear them. But then the date format is needed for EVICTION_DATE, so I restore that one. |
||
| label | ||
| street_address = "Full street address for eviction case" | ||
| Case_num = "Eviction case number" | ||
| ; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used a label statement to a descriptive label to street_address and Case_num. Ideally, we want to label all variables in permanent data sets. Do we have a code book or something that describes what all the fields are? If so, we should use that to add labels for the remaining variables. |
||
|
|
||
| run; | ||
|
|
||
| proc print data=work.evictions_addresses (obs=40); | ||
| id Case_num; | ||
| var street_address street_number street type quadrant zip_char; | ||
| run; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I limited the rows printed with |
||
|
|
||
|
|
||
| **Geocoding Macro**; | ||
| %DC_mar_geocode( | ||
| data = evictions_addresses, | ||
| staddr = street_address, | ||
| out = GeocodedEvictionsData, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed ZIP codes from the geocoding. Since many addresses are missing ZIP codes, we were getting a lot of unmatched addresses. From the LOG, 333 unmatched. It works better without the ZIP codes. This is a bit of a quirk in the geocoding macro. |
||
| streetalt_file = &_dcdata_l_path\Requests\Prog\2024\StreetAlt_GeoEvict_2024.txt | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use the macro variable &_dcdata_l_path to designate the local path name, C:\DCData\Libraries. For most people it is the same, but in the past we had machines with D: drives. &_dcdata_l_path resolves to the correct name, regardless of what it is. |
||
|
|
||
| **Macro used to finalize and save dataset**; | ||
| %Finalize_data_set( | ||
| data=GeocodedEvictionsData, | ||
| out=Evictions_2024_dc, | ||
| outlib=Requests, | ||
| label="Scheduled and executed evictions, 2024, DC", | ||
| sortby=Case_num eviction_date, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I adjusted the output data set name and label. Since we will likely have more eviction data sets, the data set name should include the year. |
||
| /** Metadata parameters **/ | ||
| printobs=0, | ||
| freqvars=year DISPOSITION ward2022, | ||
| revisions=%str(New file.) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I supressed the printed listing of data ( |
||
| ) | ||
|
|
||
| %Dup_check( | ||
| data=evictions_addresses, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this macro from our macro library to print out obs that have the same case numbers. As you can see, there are many and we need to be aware of that if we want to map or do other analysis with the data. |
||
| by=Case_num, | ||
| id=street_address eviction_date disposition, | ||
| listdups=Y | ||
| ) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added if/then statement to correct "cancelled" Spelling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @RAGarMir. Unfortunately, this code does not work (that is, it does not make the change we want). Can you tell why?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ptatian I am not sure why I does not work. After running the code and looking at the outputs I assume that the if/then statement is in the wrong place and the line with the "Cancelled" disposition is filtered out at an earlier step.
Re: StreetAlt_GeoEvict_2024.txt
I updated the file to remove the line referencing LACKLAND
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Condition statements in SAS are case-sensitive by default. If you write
disposition = 'cancelled', that is only true if the value is all lower case. But, in the data the disposition values are uppercase (CANCELLED).It's better, however, not to assume the case of the values. In a future data file they might be different. You can use the upcase() function to convert the values of disposition to all upper case for the comparison:
upcase(disposition) = 'CANCELLED'.And, then, you want to assign the new value in uppercase as well so that they are consistent.
'CANCELED'Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the default StreetAlt file and found some other problem entries. I've fixed the file in the MAR library but for your StreetAlt_GeoEvict_2024.txt file, you will want to delete these rows as well.