This script configures a local library and defines a '%json' macro to extract data. It iterates over a range of years and pages, performs POST requests via PROC HTTP to 'openapi.openfiscaldata.go.kr', and saves the raw response. JSON parsing is performed in a non-standard way via a DATA step using specific delimiters and transposition. Finally, a post-processing step applies Korean labels and filters variables.
Data Analysis
Type : EXTERNE
Data dynamically retrieved via the 'openapi.openfiscaldata.go.kr' (Open Fiscal Data) API in JSON format.
1 Code Block
DATA STEP
Explanation : Initialization of global variables (path, API key) and definition of the output library.
Explanation : Manual import and parsing of the JSON file (treated as delimited text). The 'merge' logic with offset (firstobs=2) likely serves to associate JSON keys and values.
Copied!
data raw;
infile "&dir.SeriesDataOut.txt" dsd lrecl=999999999 dlm='{}[]:,';
input raw : $2000. /* ... */;
run;
data temp;
merge raw raw(firstobs=2 rename=(raw=_raw));
if mod(_n_,2) eq 0;
run;
/* ... logique de groupe ... */
Explanation : Pivots the parsed data to transform key-value pairs (rows) into structured columns, then appends this data to the cumulative final table.
Copied!
proc transpose data=temp out=data_one(drop=_:);
by group;
id raw;
var _raw;
run;
data &lib..&data_final;
set &lib..&data_final data_one;
run;
1
PROC TRANSPOSEDATA=temp out=data_one(drop=_:);
2
BY group;
3
id raw;
4
var _raw;
5
RUN;
6
7
DATA &lib..&data_final;
8
SET &lib..&data_final data_one;
9
RUN;
5 Code Block
DATA STEP Data
Explanation : Final table cleaning: deletion of empty rows, application of column labels (in Korean) for business documentation, and retention of only the variables of interest defined in &var_want.
Copied!
/*변수명, 변수 형태 변경_start*/
data &lib .longdata_002;
set &lib .longdata_002;
if FSCL_YY="" then delete;
label FSCL_YY=회계연도;
/* ... autres labels ... */
label NRC_AMT =미수납액(원);
keep &var_want;
run;
1
/*변수명, 변수 형태 변경_start*/
2
DATA &lib .longdata_002;
3
SET &lib .longdata_002;
4
IF FSCL_YY=""THEN delete;
5
label FSCL_YY=회계연도;
6
/* ... autres labels ... */
7
label NRC_AMT =미수납액(원);
8
keep &var_want;
9
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.