Wednesday, April 26, 2017

SAS: Crosscorrelations over time in PROC ARIMA

proc sort data=sashelp.pricedata out=test;
    by productname regionname;
run;


proc arima data=test ;
  by productname regionname;
  identify var=sale crosscorr=price;
  ods output AutoCorrGraph=correlations;
run;



Friday, March 17, 2017

SAS: put   in html



How to include an   in HTML written by SAS.

Declaration:

    * Source: http://marc.info/?l=sas-l&m=116624302014032&w=2 ;
    %let nbsp=%nrstr(&nbsp);


Use:

    put "Part Number: ";
    put "" PART_NUMBER "";
    put " (" PART_DESCRIPTION +(-1) ")";



("mark" tag creates yellow-highlighted text)

Result:



Friday, November 11, 2016

R: list vs. (c)ombine

list vs. (c)ombine

(Lists can hold different types of objects; keeps them distinct.)




> mylist = list(x=1:5, y=c("a", "b", "c"), z=c(T,F,T))
> mylist
$x
[1] 1 2 3 4 5

$y
[1] "a" "b" "c"

$z
[1]  TRUE FALSE  TRUE

> mycombine = c(x=1:5, y=c("a", "b", "c"), z=c(T,F,T))
> mycombine
     x1      x2      x3      x4      x5      y1 
    "1"     "2"     "3"     "4"     "5"     "a" 
     y2      y3      z1      z2      z3 
    "b"     "c"  "TRUE" "FALSE"  "TRUE" 


 
 

Wednesday, November 9, 2016

R: assign function

This will come in handy someday...


    x = "y"
    assign(x, c(3:6))



The result is a variable x with value "y", and a vector y with values int[1:4] 3 4 5 6




Wednesday, October 19, 2016

SAS - Assign LIBNAME to WORK



Assign libname to WORK...


    %let workLocation=%sysfunc(getoption(work));
    libname bill "&workLocation.";


Source: http://stackoverflow.com/questions/31051172/how-can-i-assign-libname-to-work-data-library-in-sas

SAS - Example of COBOL-like structure

An example of COBOL-like structure in a SAS program.



/*
* BQ 20161018
* Match rule violations to reportable injuries.
* Append Rptl_Dmy to output rule violation.
* Logic assumes both input files sorted by EmployeeID and Date.
* I am doing this because there are so many rules, I need to
* thin the herd before attempting any real association analysis.
*/

%let MAX_DAYS_VIOLATION_TO_INJURY = 30;

data
      &TBL_ALL_RULES_MATCHED
      &TBL_INJURIES_WITHOUT_VIOLATION
  ;

retain match_found;

* Begin what I always called "mainline" in COBOL. ;

link READ_RULE;
link READ_INJURY;
do while (eof_rule = 0 AND eof_injury = 0);
      link PROCESS_RTN;
end;
link WRAPUP;
return; * end "mainline";

READ_RULE:
      set &TBL_ALL_RULES
           (where=(date >= &GLBL_MIN_INJURY_DATE)) end=eof_rule;
      return; * end READ_RULE ;

READ_INJURY:
      set &TBL_REPORTABLE_INJURIES_ONLY
           (rename=(EmployeeID = injEmployeeID Date = injDate)) end=eof_injury;
      match_found = 0;
      return; * end READ_INJURY;

PROCESS_RTN:
      if (EmployeeID < injEmployeeID) then link RULE_LOW;
      else if (EmployeeID > injEmployeeID) then link INJURY_LOW;
      else if (Date < (injDate - &MAX_DAYS_VIOLATION_TO_INJURY)) then link RULE_LOW;
      else if (Date >= (injDate - &MAX_DAYS_VIOLATION_TO_INJURY) AND
                 Date <= (injDate + &MAX_DAYS_VIOLATION_TO_INJURY)) then link MATCH;
      else link INJURY_LOW;
      return; * end PROCESS_RTN;

RULE_LOW:
      reportable_injury = 0;
      lead_time_in_days = .;
      output &TBL_ALL_RULES_MATCHED;
      link READ_RULE;
      return; * end RULE_LOW;

INJURY_LOW:
      if (match_found = 0) then do;
           output &TBL_INJURIES_WITHOUT_VIOLATION;
      end;
      link READ_INJURY;
      return; * end INJURY_LOW;

MATCH:
      match_found = 1;
      reportable_injury = 1;
      lead_time_in_days = injDate - Date;
      output &TBL_ALL_RULES_MATCHED;
      * what if violation on Jan 1, violation on Jan 2, injury on Jan 3 ? ;
      * that is why I am only going to read next Rule record (not Injury). ;
      link READ_RULE;
      return; * end MATCH;

WRAPUP:
      do while (eof_rule = 0);
           link RULE_LOW;
      end;
      do while (eof_injury = 0);
           link INJURY_LOW;
      end;
      return;

run;