Data is managed directly within an external SPARQL endpoint, accessible via `http://localhost:8890/sparql/`. The script proceeds with 'creating' this data via a SPARQL `INSERT DATA` instruction and retrieving it via a SPARQL `SELECT *` instruction. Although the script initiates data creation, the data resides in a third-party database, making it an external source from SAS's perspective.
1 Code Block
Configuration and Macro Inclusion
Explanation : This block configures SAS options to display macro execution logs (`mprint`, `mlogic`) and includes the 'sparqlquery.sas' file, which contains the definitions of the `%sparqlupdate` and `%sparqlquery` macros needed to interact with a SPARQL endpoint.
Explanation : Call to the `%sparqlupdate` macro to send a SPARQL `INSERT DATA` instruction to the specified endpoint. This instruction adds seven triples (representing books with their titles) to the `<http://example/bookStore>` graph of the SPARQL database. The `debug=Y` parameter enables detailed execution logging.
Copied!
%sparqlupdate(
endpoint=http://localhost:8890/sparql/update,
update=%str(
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT DATA
{
GRAPH <http://example/bookStore> {
<http://example/book1> dc:title "A new book 1" .
<http://example/book2> dc:title "A new book 2" .
<http://example/book3> dc:title "A new book 3" .
<http://example/book4> dc:title "A new book 4" .
<http://example/book5> dc:title "A new book 5" .
<http://example/book6> dc:title "A new book 6" .
<http://example/book7> dc:title "A new book 7" .
}
}
),
resultdsn=updateresult,
debug=Y
);
1
%sparqlupdate(
2
endpoint=http://localhost:8890/sparql/update,
3
update=%str(
4
PREFIX dc: 1.1/>
5
INSERT DATA
6
{
7
GRAPH {
8
dc:title "A new book 1" .
9
dc:title "A new book 2" .
10
dc:title "A new book 3" .
11
dc:title "A new book 4" .
12
dc:title "A new book 5" .
13
dc:title "A new book 6" .
14
dc:title "A new book 7" .
15
}
16
}
17
),
18
resultdsn=updateresult,
19
debug=Y
20
);
3 Code Block
Macro %sparqlquery
Explanation : Execution of a SPARQL `SELECT *` query via the `%sparqlquery` macro. This query aims to retrieve all subjects (`?s`) and their titles (`?o`) from the graph, corresponding to the previously inserted data. The results are stored in the SAS table `query` for later use in SAS.
Explanation : The `PROC PRINT` procedure is used to display the content of the SAS table `query`. This allows visualizing the results of the SPARQL query and confirming that the data has been correctly retrieved from the external endpoint.
Copied!
proc print data=query width=min;
run;
1
PROC PRINTDATA=query width=min;
2
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.
Copyright Info : Program : example-localhost-virtuoso-01.sas
Purpose : Basic test of SAS-SPARQLwrapper using a query and local server
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.