Tuesday, July 24, 2012

SAS proc transpose for 2 Columns

We have a data set with columns Name, Month, Day and Sale. And we require a variable like Sale in January Monday for against each name.

Wednesday, July 18, 2012

Difference between two consecutive rows in SAS



Dataset is shown on right side. Here Visit, Time and Page are given and we need to calculate the duration by subtracting two consecutive rows.

E.g
Duration of Page "A" in Visit 1 is 23:39:23 - 23:34:10.
For Calculating Time difference we first need to convert this into time variable.

data libname.dataset;
set libname.dataset;
time1 = hms (scan(time,1,':'), scan(time,2,':'), scan(time,3,':');
run;

Now this time can be use for calculation. Now, Try the  macro below for calculation of duration. For Difference calculation I am using proc sql .

Note: Duration of last page of every visit is marked as Zero (as it can't be calculated).


Copy the macro below in file and for using type
%include "<filename complete path>";

%time_calc( libname,input_dataset,output_dataset,visit,time1,Duration);

Macro

Wednesday, July 4, 2012