/******************************************************************************\ * $Id: AIO2RDF.sas * * Copyright(c) 2016 by SAS Institute Inc., Cary, NC USA 27513 * * Name : AIO2RDF.sas * * Purpose : This program reads Input/Output strucuted SAS dataset and * generates RDF Turtle(ttl) file * * Author : Sandeep Juneja(SJ) * * Support : SAS(r) Solutions OnDemand * * Input : * * Output : * * * Parameters : (if applicable) * * Dependencies/ * Assumptions : * * Usage : * * History: * CHGID DATE User Comment * 0001 20AUG2016 SJ Creation /******************************************************************************/ /*---------------------------------------------------------------------- * SAMPLE code for parsing the output from SCAPROC and creating a * dataset with inputs and output. * * Macro variables used: * scaprocout - textual output of SCAPROC to be analyzed * * Librefs used: * mywork - library where the output data set will be stored * * SAS INSTITUTE INC. IS PROVIDING YOU WITH THE COMPUTER SOFTWARE CODE * INCLUDED WITH THIS AGREEMENT ("CODE") ON AN "AS IS" BASIS, AND * AUTHORIZES YOU TO USE THE CODE SUBJECT TO THE TERMS HEREOF. BY USING * THE CODE, YOU AGREE TO THESE TERMS. YOUR USE OF THE CODE IS AT YOUR * OWN RISK. SAS INSTITUTE INC. MAKES NO REPRESENTATION OR WARRANTY, * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND * TITLE, WITH RESPECT TO THE CODE. * * The Code is intended to be used solely as part of a product * ("Software") you currently have licensed from SAS Institute Inc. or * one of its subsidiaries or authorized agents ("SAS"). The Code is * designed to either correct an error in the Software or to add * functionality to the Software, but has not necessarily been tested. * Accordingly, SAS makes no representation or warranty that the Code * will operate error-free. SAS is under no obligation to maintain or * support the Code. * * Neither SAS nor its licensors shall be liable to you or any third * party for any general, special, direct, indirect, consequential, * incidental or other damages whatsoever arising out of or related to * your use or inability to use the Code, even if SAS has been advised of * the possibility of such damages. * * Except as otherwise provided above, the Code is governed by the same * agreement that governs the Software. If you do not have an existing * agreement with SAS governing the Software, you may not use the Code. * *----------------------------------------------------------------------*/ %macro rdf_prefix(); put "@prefix rdf: ."; put "@prefix rdfs: ."; put "@prefix xsd: ."; put "@prefix aio: ."; put " "; %mend rdf_prefix; %macro rdf_meta(); %if %symexist(createdBy) %then %do; put @5 "" '"' "%sysfunc(strip(&createdBy))" '"' "^^;"; %end; put @5 "" '"' "%sysfunc(strip(&createdDate))" '"' "^^;"; %if %symexist(modifiedBy) %then %do; put @5 "" '"' "%sysfunc(strip(&modifiedBy))" '"' "^^;"; %end; put @5 "" '"' "%sysfunc(strip(&modifiedDate))" '"' "^^;"; put @5 "" '"' "%sysfunc(strip(&fileSize.))" '"' "^^;"; %mend rdf_meta; %macro aio2rdf(aio_dset=,rdf_file=); %let aio_dset=%sysfunc(tranwrd(&aio_dset,%str(\),%str(/))); %let dset_path=%substr(&aio_dset,1,%sysfunc(find(&aio_dset,%str(/),-%length(&aio_dset)))-1); %let dset_name=%scan(%substr(&aio_dset,%sysfunc(find(&aio_dset,%str(/),-%length(&aio_dset)))+1),1,%str(.)); %put aio_dset=&aio_dset; %put dset_path=&dset_path dset_name=&dset_name; libname aio "&dset_path"; data m_aio; set aio.&dset_name.; run; filename tmp "&rdf_file."; data _null_; file tmp; %rdf_prefix(); run; %let idx=%sysfunc(open(m_aio)); %let NObs=%sysfunc(attrn(&idx,NOBS)); %syscall set(idx); data _null_; file tmp mod; %do k=1 %to &NObs; %let rc=%sysfunc(fetchobs(&idx,&k)); * Variable Derivations; %let sas_file_name = %scan(&sas_task,-1,%str(/)); %*put &sas_task &sas_file_name &order_id; %let file_path_path=%substr(&file_path,1,%sysfunc(find(&file_path,%str(/),-%length(&file_path)))-1); %*let file_path_name=%scan(%substr(&file_path,%sysfunc(find(&file_path,%str(/),-%length(&file_path)))+1),1,%str(.)); %let file_path_name=%substr(&file_path,%sysfunc(find(&file_path,%str(/),-%length(&file_path)))+1); %*put &file_path_path &file_path_name; %if (&type=%str(JOBSTARTTIME)) %then %do; put @1 "# definition"; put @1 " rdfs:range ."; put @1 " rdfs:domain ."; put @1 " rdfs:domain ."; put @1 " "; put @1 "# Program"; put @1 " " '"' "&file_path_path" '"' "^^;"; %rdf_meta() put @5 "" '"' "%sysfunc(strip(&timeinfo))" '"' "^^;"; %end; %else %if (&type=%str(JOBENDTIME)) %then %do; put @5 "" '"' "%sysfunc(strip(&timeinfo))" '"' "^^."; put @1 " "; %end; %else %if (&type=%str(INPUT)) %then %do; put @1 "# Input"; put @1 " " '"' "&file_path_path" '"' "^^;"; %rdf_meta() put @5 "rdfs:range ."; put @1 " "; %end; %else %if (&type=%str(OUTPUT)) %then %do; put @1 "# Output"; put @1 " " '"' "&file_path_path" '"' "^^;"; %rdf_meta() put @5 "rdfs:range ."; put @1 " "; %end; %end; * end of do loop; run; %let id=%sysfunc(close(&idx)); %mend aio2rdf; * Sample Call; %*aio2rdf(aio_dset=%str(C:\AnalyzeIO\RDF\template\master_io.sas7bdat), rdf_file=%str(C:\AnalyzeIO\RDF\template\rdf_dm.ttl));