Scriptathon 2014 Code for Retreiving Inputs

From PHUSE Wiki
Revision as of 09:21, 3 September 2015 by DanteDT (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

SAS Code for accessing datasets

  • To understand why this works, despite absence of physical SAS library name on the libname statement, see documentation for the XML Libname Engine.
  • Basically, since the fileref and the libref names match, SAS uses the same-name fileref for the libref definition.

From PhUSE-CSS 2015, the scripts repository will be moving to GitHub. Here is a SAS example of accessing a github data set:

 filename source url "https://raw.github.com/cjbcross/phuseTest/master/adsl.xpt";
 libname source xport ;
 
 data work.adsl ;
   set source.adsl ;
   keep usubjid ;
 run ;
 
 libname source clear;
 filename source clear;
 
 proc print data=work.adsl ;
   title1 "A test of accessing datasets from the PhUSE Code Repository";
 run ;
 

R Code for accessing datasets

Again, below version contains updated reference to new GitHub location:

 library(SASxport)
 library(httr)
 r <- GET("https://raw.github.com/cjbcross/phuseTest/master/adsl.xpt")
 bin <- content(r, "raw")
 
 # EDIT PATHNAME TO REFLECT YOUR WORKING/TEMP DIRECTORY
 writeBin(bin, "myfile.txt")
 adsl <- read.xport("~/myfile.txt")
 
 plot(adsl$AGE,adsl$WEIGHTBL)
 title(main="ADSL: Baseline Weight vs Age")
 
 # CLEANUP FILE
 if (file.exists("myfile.txt")) file.remove("myfile.txt")

Continuation of 2014 page with Google Code xpt file references

SAS Code for accessing datasets

 filename source url "http://phuse-scripts.googlecode.com/svn/trunk/scriptathon2014/data/adsl.xpt" ;
 libname source xport ;
 data work.adsl ;
   set source.adsl ;
   keep usubjid ;
 run ;
 proc print data=work.adsl ;
   title1 "A test of accessing datasets from the PhUSE Code Repository" ;
   run ;
 

R Code for accessing datasets

 library(SASxport)
 adsl <- read.xport(file="http://phuse-scripts.googlecode.com/svn/trunk/scriptathon2014/data/adsl.xpt")
 plot(adsl$AGE,adsl$WEIGHTBL)
 title(main="ADSL: Baseline Weight vs Age")

SAS Code for accessing RAVE CSV files

 filename clindata "C:\Users\am00404163\Desktop\dm.csv";
 proc http
   out=clindata
   url="https://innovate.mdsol.com/RaveWebServices/studies/Mediflex(DEV)/datasets/regular/DM.csv"
   webUserName="name"
   webPassword="password"
   method="get"
  ;
  run;
 proc import datafile=clindata dbms=csv out=dm replace;
   datarow=2;
   getnames=yes;
   guessingrows=32767;
 run;
 data dm ;
   set dm (where=(userID ^= 'EOF'));
   run;