U.S. flag

An official website of the United States government

Access the API: SAS Software

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.

Step 1: Build input JSON file

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.

DSID API Example Response

Step 2: Export to JSON file

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.

DSID API Example Response

Step 3: Set up filepaths

This input list can be converted to JSON format using the toJSON function from the jsonlite package.

DSID API Example Response

Step 4: Send a POST request

Use the proc HTTP procedure to build and send an API request. There are 4 arguments needed:

  • method, the type of API request: POST,
  • URL, the DSID API web URL: https://dsid-api-dev.app.cloud.gov/v1/calculators,
  • in, your input file variable from Step 2, and
  • out, your output file variable from Step 2
  • ct, the content type you will be passing: “application/json”
DSID API Example Response

Run the proc step. In the log file, a successful request should show a Status of “200 OK”.

DSID API Example Response

Step 5: View and save output

To convert the JSON output back into a SAS dataset, use a JSON libname statement to refer to our output file.

DSID API Example Response

The results_table dataset now contains one row with columns for each of the fields returned from the API.

DSID API Example Response

You can also work with the JSON output in other software programs. See the “Converting JSON Data” API page for importing into Excel.