Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions Prog/2022/Export_weight_files.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/**************************************************************************
Program: Export_weight_files.sas
Library: PresCat
Project: NeighborhoodInfo DC
Author: P. Tatian
Created: 03/30/16
Version: SAS 9.4
Environment: Local Windows session (desktop)
GitHub issue: 74

Description: Export tract weighting files CSV, with
data dictionary.

Requested by Michael Kalish for Housing Insights project.

Modifications:
**************************************************************************/

%include "\\sas1\DCdata\SAS\Inc\StdLocal.sas";

** Define libraries **;


/** Macro Export - Start Definition **/

%macro Export( data=, out=, desc= );

%local lib file;

%if %scan( &data, 2, . ) = %then %do;
%let lib = work;
%let file = &data;
%end;
%else %do;
%let lib = %scan( &data, 1, . );
%let file = %scan( &data, 2, . );
%end;

%if &out = %then %let out = &file;

%if %length( &desc ) = 0 %then %do;
proc sql noprint;
select memlabel into :desc from dictionary.tables
where upcase(libname)=upcase("&lib") and upcase(memname)=upcase("&file");
quit;
run;
%end;

filename fexport "&out_folder\&out..csv" lrecl=2000;

proc export data=&data
outfile=fexport
dbms=csv replace;

run;

filename fexport clear;

proc contents data=&data out=_cnt_&out (keep=varnum name label label="&desc") noprint;

proc sort data=_cnt_&out;
by varnum;
run;

%let file_list = &file_list &out;

%mend Export;

/** End Macro Definition **/


/** Macro Dictionary - Start Definition **/

%macro Dictionary( );

%local desc;

** Start writing to XML workbook **;

ods listing close;

ods tagsets.excelxp file="&out_folder\Data dictionary.xls" style=Normal
options( sheet_interval='Proc' orientation='landscape' );

** Write data dictionaries for all files **;

%local i k;

%let i = 1;
%let k = %scan( &file_list, &i, %str( ) );

%do %until ( &k = );

proc sql noprint;
select memlabel into :desc from dictionary.tables
where upcase(libname)="WORK" and upcase(memname)=upcase("_cnt_&k");
quit;
run;

ods tagsets.excelxp
options( sheet_name="&k"
embedded_titles='yes' embedded_footnotes='yes'
embed_titles_once='yes' embed_footers_once='yes' );

proc print data=_cnt_&k label;
id varnum;
var name label;
label
varnum = 'Col #'
name = 'Name'
label = 'Description';
title1 bold "Data dictionary for file: &k..csv";
title2 bold "&desc";
title3 height=10pt "Prepared by NeighborhoodInfo DC on %left(%qsysfunc(date(),worddate.)).";
footnote1;
run;

%let i = %eval( &i + 1 );
%let k = %scan( &file_list, &i, %str( ) );

%end;

** Close workbook **;

ods tagsets.excelxp close;
ods listing;

run;

%mend Dictionary;

/** End Macro Definition **/


%global file_list out_folder;

** DO NOT CHANGE - This initializes the file_list macro variable **;
%let file_list = ;

** Fill in the folder location where the export files should be saved **;
%let out_folder = &_dcdata_default_path\Requests\Raw\2022;

** Export individual data sets **;
%Export( data=General.Wt_tr10_cl17 )
%Export( data=General.Wt_tr20_cl17 )
%Export( data=General.Wt_tr10_ward22 )
%Export( data=General.Wt_tr20_ward22 )

** Create data dictionary **;
%Dictionary()

run;


**** 2020 tract name crosswalk file ****;
**** Format is "11001000100":"1":"Tract 1" ****;

data _null_;

set General.Geo2020;
where geo2020 =: '11';

file "&out_folder\DC Census tract crosswalk 2020.txt";

length buff $ 200;

buff =
trim( quote( geo2020 ) ) || ':' ||
trim( quote( trim( substr( put( geo2020, $geo20a. ), 10 ) ) ) ) || ':' ||
quote( ( trim( substr( put( geo2020, $geo20a. ), 4 ) ) ) );

put buff;

run;