PING
0.9
Statistical data handling and processing in production environment
|
Export EU-SILC bulk datasets from SAS format (.sas7bdat
) to any format supported by PROC FORMAT
.
survey
: type of the survey; this is represented by any of the character values defined in the global variable G_PING_SURVEYTYPES
, i.e. as:X
. C
or CROSS
for a cross-sectional survey,L
or LONG
for a longitudinal survey,E
or EARLY
for an early survey,time
: a single selected year of interest;geo
: string(s) representing the ISO-code(s) of (a) country(ies); note that when geo
is not passed and src=raw
(see below), the output parameters _path_
and _ds_
cannot be defined: only _ftyp_
can be returned (see below); in all other cases, geo
is ignored;db
: (option) database(s) to retrieve; it can be any of the character values defined through the global variable G_PING_BASETYPES
, i.e.:D
for household register/D file,H
for household/H file,P
for personal register/P file,R
for register/R file, so as to represent the corresponding bulk databases (files); by default,db=&G_PING_BASETYPES
;src
: (option) string defining the source location where to look for bulk database; this can be either the full path of the directory where to search in, or any of the following strings:bdb
, ibid with the value of G_PING_BDB
,pdb
, ibid with the value of G_PING_PDB
,idb
, ibid with the value of G_PING_IDB
,udb
, ibid with the value of G_PING_UDB
; note that the latter four cases are independent of the parameter chosen for geo
; note also that src=bdb
and src=idb
are incompatible with survey<>X
; furthermore, when src=idb
, the parameter db
is ignored; by default, src
is set to the value of G_PING_RAWDB
(e.g. &G_PING_ROOTPATH/main
) so as to look for raw data;cds_transxyear, clib
: (options) configuration file storing the the yearly definition of microdata transmission files' format, and library where it is actually stored; for further description of the table, see %meta_transmissionxyear and %silc_db_locate._ofn_
: name (string) of the macro variable storing the output exported file name.odir
: (option) output directory/library to store the converted dataset; by default, it is set to:sysget(SAS_EXECFILEPATH)
if you are running on a Windows server,ilib
(i.e., sysfunc(pathname(&ilib))
) otherwise.Let us export some bulk datasets from the so-called BDB into Stata
native format (dta
):
In our current environment (see G_PING_ROOTPATH
definition), the following output files will be created:
%silc_ds_extract, %silc_db_locate, %ds_export, %meta_transmissionxyear. **/
/* credits: gjacopo */
macro silc_db_export(survey /* Input type of the survey (REQ) */ , time /* Input year under consideration (REQ) */ , geo= /* Input country under consideration (REQ) */ , odir= /* Full path of output directory (OPT) */ , ofn= /* Name of the variable storing the output filename (OPT) */ , fmt= /* Format of import (OPT) */ , db= /* Input database to retrieve (OPT) */ , src= /* Input location of bulk data source (OPT) */ , cds_transxyear= /* Name of configuration file storing the type of transmission files (OPT) */ , clib= /* Name of the configuration library (OPT) */ ); local _mac; let _mac= macro_put(&_mac);
/************************************************************************************/ /** checkings/settings **/ /************************************************************************************/
local YEARINIT;
/* GEO: check/set input ISO-code
/* TIME: check/set */ if symexist(G_PING_INITIAL_YEAR) then let YEARINIT= else let YEARINIT=2002;
if error_handle(ErrorInputParameter, par_check(&time, type=INTEGER, range=&YEARINIT) NE 0, mac=&_mac, txt=quote(!!! Wrong type/value for input TIME !!!)) then goto exit; else let yy=substr(&time,3,2);
/* ODIR: default setting and checking odir */ if macro_isblank(odir) then do; if symexist(_SASSERVERNAME) then /* working with SAS EG */ let odir=&G_PING_ROOTPATH/_egp_path(path=drive); else if &sysscp = WIN then do; /* working on Windows server */ let odir=sysget(SAS_EXECFILEPATH); if not macro_isblank(odir) then let odir=qsubstr(&odir, 1, length(&odir)-length(sysget(SAS_EXECFILENAME)); end; end; if error_handle(ErrorInputParameter, macro_isblank(odir) EQ 1, mac=&_mac, txt=quote(!!! Output directory upcase(&odir) not set !!!)) or error_handle(ErrorInputParameter, dir_check(&odir) NE 0, mac=&_mac, txt=quote(!!! Output directory upcase(&odir) does not exist !!!)) then goto exit;
/* FMT */ if macro_isblank(fmt) then let fmt=csv;
/************************************************************************************/ /** actual computation **/ /************************************************************************************/
local _i _ofn ds path SEP; let SEP=quote( ); let _ofn=;
silc_db_locate(&survey, &time, geo=&geo, db=&db, src=&src, ds=ds, path=path, cds_transxyear=&cds_transxyear, clib=&clib, lazy=YES);
if not macro_isblank(ofn) then let &_ofn_=;
do i=1 to list_length(&ds); libname tmplib "%scan(&path,&_i, &SEP)"; let idsn=scan(&ds, &_i); ds_export(&idsn, odir=&odir, _ofn=_ofn, fmt=&fmt, ilib=tmplib); libname tmplib clear; if not macro_isblank(ofn) then let &_ofn_=&&&_ofn_ end;
exit: mend silc_db_export;
macro example_silc_db_export; if symexist(G_PING_SETUPPATH) EQ 0 then do; if symexist(G_PING_ROOTPATH) EQ 0 then do; put WARNING: !!! PING environment not set - Impossible to run &sysmacroname !!!; put WARNING: !!! Set global variable G_PING_ROOTPATH to your PING install path !!!; goto exit; end; else do; let G_PING_PROJECT= 0EUSILC; let G_PING_SETUPPATH=&G_PING_ROOTPATH./PING; let G_PING_DATABASE= /ec/prod/server/sas/0eusilc; include "&G_PING_SETUPPATH/library/autoexec/_eusilc_setup</em>.sas"; _default_setup_; end; end;
local _i survey time src ofn odir fmt db; let ofn=;
/* we currently launch this example in the highest level (1) of debug only */ if symexist(G_PING_DEBUG) then let olddebug= else do; global G_PING_DEBUG; let olddebug=0; end; let G_PING_DEBUG=1;
let survey=CROSS; let time=2015; let src=BDB; let db=D H R; let fmt=dta; let odir=/ec/prod/server/sas/0eusilc; put Given the following parameters:; put - survey= put - time= put - src= put - db= put - fmt= put - odir= silc_db_export(&survey, &time, odir=&odir, ofn=ofn, fmt=dta, db=&db, src=&src); put the following output files will be created:; do _i=1 to list_length(&ofn); put - scan(&ofn, &_i, quote( )); end;
/* reset the debug as it was (if it ever was set) */ let G_PING_DEBUG=
put;
exit: mend _example_silc_db_export;
/* Uncomment for quick testing options NOSOURCE MRECALL MLOGIC MPRINT NOTES; _example_silc_db_export;