BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
meckssh0
Calcite | Level 5
Hi, I am trying to get qualtrics surveys to read into SAS directly using the PROC HTTP method. I am having trouble getting SAS to destinguish between surveys from qualtrics and call them in, so I moved to R. My R code is below and allows me to call in both surveys into R just fine. However, I need to do this in SAS, so can someone help me translate this into SAS please? I also have my preliminary SAS code below, but it isn't complete or working (seems like there needs to be a way to call each individual survey as well). Thank you!
filename response temp encoding="utf-8" lrecl= 1000000;
proc http
url="https://HOSTNAME.ca1.qualtrics.com/WRAPI/ControlPanel/api.php?Request=getSurveys&User=USERID$Token=TOKEN&version=2.4&Format=JSON"
method="GET"
out= response;
run;
 
 
#############R CODE############################
## qualtRics required (in R CRAN archives)
require(qualtRics)
# sets path so R knows where to look for my files
setwd("C/Users/#########PATH##########")
# print the current directory
getwd()
## Input appropriate API token and URL
registerOptions(api_token="TOKEN", root_url="https://ROOT.ca1.qualtrics.com")
## gets specific surveys
Survey1<- getSurvey(surveyID = "SURVEYID")
Survey2<- getSurvey(surveyID ="SURVEYID" )
#########################################
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

My assumption has been that you'd like to get either a refresh of survey responses or new survey responses on a regular schedule and are trying to access the survey responses automatically. Is this correct?

 

The proposed approach is the Qualtrics API suggestion, not mine. 

 

I would not recommend building something on their old API because at some point they will stop supporting it. That's ultimately your choice, however. At this point, from what I've seen, the Qualtrics API creates a zip file with the requested data and you can download that. 

 

https://api.qualtrics.com/docs/common-tasks

 

The zip files are downloaded via the API and then you can read them once they're local. 

 

I recently build something similar using the Statistics Canada 'API' which also downloads ZIP files. 

 

1. Download file

2. Store in Work library

3. Find element name in file

4. Read file directly from ZIP - no need to unzip in SAS at least

5. When my SAS session ends, the file will be deleted automatically, or I could have added this to my process. 

 

The code for this is here: 

https://gist.github.com/statgeek/5c8f4e769e898353d7e8115610f5ad5e

 

IMO, these aren't great API functions (StatCan or Qualtrics) but it is the reality.


@meckssh0 wrote:

These zip files are not read over an API though, right? I need it to be called in over an API. 

Thank you. 




 

 

 

View solution in original post

5 REPLIES 5
Reeza
Super User

R is using a package that someone else prebuilt so it's actually masking the work that's being done in that package there. This makes it harder to replicate without looking up the Qualtrics API. 

 

It appears that type of functionality was specifically written by an R user, but not something Qualtrics supports. The Qualtrics API seems to support downloading all responses at once or adding filters, but what happens is:

 

1. Request a data download -> qualtrics preps the file

2. Wait for file to be created

3. Download file as zip

4. Unzip file

 

Is that an approach that will work for you?

 

https://api.qualtrics.com/docs/common-use-case-examples

 


@meckssh0 wrote:
Hi, I am trying to get qualtrics surveys to read into SAS directly using the PROC HTTP method. I am having trouble getting SAS to destinguish between surveys from qualtrics and call them in, so I moved to R. My R code is below and allows me to call in both surveys into R just fine. However, I need to do this in SAS, so can someone help me translate this into SAS please? I also have my preliminary SAS code below, but it isn't complete or working (seems like there needs to be a way to call each individual survey as well). Thank you!
filename response temp encoding="utf-8" lrecl= 1000000;
proc http
url="https://HOSTNAME.ca1.qualtrics.com/WRAPI/ControlPanel/api.php?Request=getSurveys&User=USERID$Token=TOKEN&version=2.4&Format=JSON"
method="GET"
out= response;
run;
 
 
#############R CODE############################
## qualtRics required (in R CRAN archives)
require(qualtRics)
# sets path so R knows where to look for my files
setwd("C/Users/#########PATH##########")
# print the current directory
getwd()
## Input appropriate API token and URL
registerOptions(api_token="TOKEN", root_url="https://ROOT.ca1.qualtrics.com")
## gets specific surveys
Survey1<- getSurvey(surveyID = "SURVEYID")
Survey2<- getSurvey(surveyID ="SURVEYID" )
#########################################

 

 

 

 

meckssh0
Calcite | Level 5

I appreciate your response. Yes, the zipfile might work, but I am unsure of how to get SAS to run the import as a zipfile. Does it then turn it to XML format or JSON? All the qualtrics code is in Python, so any help with SAS would be much appreciated. 

Thank you!

Reeza
Super User

I think the zip file is CSV so that should make it easier to analyze. So once you have the file, you can unzip and read it. 

 

This may help you get started:

https://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in...

 

 

meckssh0
Calcite | Level 5

These zip files are not read over an API though, right? I need it to be called in over an API. 

Thank you. 

Reeza
Super User

My assumption has been that you'd like to get either a refresh of survey responses or new survey responses on a regular schedule and are trying to access the survey responses automatically. Is this correct?

 

The proposed approach is the Qualtrics API suggestion, not mine. 

 

I would not recommend building something on their old API because at some point they will stop supporting it. That's ultimately your choice, however. At this point, from what I've seen, the Qualtrics API creates a zip file with the requested data and you can download that. 

 

https://api.qualtrics.com/docs/common-tasks

 

The zip files are downloaded via the API and then you can read them once they're local. 

 

I recently build something similar using the Statistics Canada 'API' which also downloads ZIP files. 

 

1. Download file

2. Store in Work library

3. Find element name in file

4. Read file directly from ZIP - no need to unzip in SAS at least

5. When my SAS session ends, the file will be deleted automatically, or I could have added this to my process. 

 

The code for this is here: 

https://gist.github.com/statgeek/5c8f4e769e898353d7e8115610f5ad5e

 

IMO, these aren't great API functions (StatCan or Qualtrics) but it is the reality.


@meckssh0 wrote:

These zip files are not read over an API though, right? I need it to be called in over an API. 

Thank you. 




 

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3763 views
  • 0 likes
  • 2 in conversation