To query the DSID API using the SAS programming language, you can construct a POST request to send data to the API and retrieve results. This page is intended for users who are already familiar with using SAS.
There are multiple options for SAS procedures that can send API requests. This example shows how proc http and proc json can be used to reach the DSID API. To download the full SAS code shown in this page, use this link.
Suppose you want to estimate calcium levels in adults using a label amount of 200mg. Use a datalines statement to define the 4 required fields. Note that the study_code, ingredient, and unit columns are character while the label_amount column is numeric.
To pass data into the API, we will need to convert it to JSON format. The proc json procedure can be used to write a SAS dataset to a JSON file; be sure to include the “nosastags” option to keep it formatted properly for the DSID API.
This input list can be converted to JSON format using the toJSON function from the jsonlite package.
Use the proc HTTP procedure to build and send an API request. There are 4 arguments needed:
Run the proc step. In the log file, a successful request should show a Status of “200 OK”.
To convert the JSON output back into a SAS dataset, use a JSON libname statement to refer to our output file.
The results_table dataset now contains one row with columns for each of the fields returned from the API.
You can also work with the JSON output in other software programs. See the “Converting JSON Data” API page for importing into Excel.