The script initializes connection parameters (API key) and directory. A '%json' macro manages the extraction loop over a defined range of codes/dates. For each iteration, PROC HTTP retrieves JSON data. This data is parsed unconventionally using delimiters in a DATA STEP (reading as a flat file), followed by transposition to structure the data. Finally, a global step assembles the results and applies Korean column labels. The code contains hardcoded Windows paths and concatenation logic (L001_0-L001_200) which could fail if not all datasets in the range exist.
Data Analysis
Type : EXTERNAL
Data is extracted from the 'openapi.openfiscaldata.go.kr' API. The script attempts to write and reread temporary files in 'D:\OneDrive\...', which is incompatible with the current Linux SAS Viya environment without modifying the '&dir' path.
1 Code Block
MACRO
Explanation : Initialization of environment variables, API key, and output library. The 'dir' path points to a Windows location.
Explanation : Core processing: the macro iterates over requests, downloads JSON via PROC HTTP, and uses a manual parsing approach (input with JSON delimiters) to transform the hierarchical structure into a SAS table via PROC TRANSPOSE.
Copied!
%macro json(data_final, String05, date_s, date_e);
%do date_want=&date_s %to &date_e;
/* ... construction URL ... */
proc http out=out url="&url" method="post" ct="application/json";
run;
data raw;
infile "&dir.SeriesDataOut.txt" dsd lrecl=999999999 dlm='{}[]:,';
input raw : $2000. @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json; /* Correction de l'artefact ' @code_sas_json...' */
if _n_=5 then call symput('check', scan(raw,2));
run;
/* ... logique de transposition et merge ... */
%end;
%mend;
%json(data_final=longdata_001, String05=http://openapi.openfiscaldata.go.kr/VWFOEM, date_s=161, date_e=163);
Explanation : Final consolidation. Attempts to read a fixed range of tables (L001_0 to L001_200), applies Korean labels, and filters variables. Warning: this step will fail if the macro has not generated all tables from 0 to 200.
Copied!
data &lib .longdata_001;
set L001_0-L001_200;
label FSCL_YY= 회계년도;
label EXE_M =집행월;
/* ... autres labels ... */
keep &var_want;
if FSCL_YY="" then delete;
run;
1
DATA &lib .longdata_001;
2
SET L001_0-L001_200;
3
label FSCL_YY= 회계년도;
4
label EXE_M =집행월;
5
/* ... autres labels ... */
6
keep &var_want;
7
IF FSCL_YY=""THEN delete;
8
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.