Tuesday, July 5, 2016

SAS: PROC SQL, FEEDBACK option

PROC SQL will show details about output files in the SAS log, but unfortunately does not (currently) list input files. Rather than attempt to parse the input code, you can probably get what you want my adding the FEEDBACK option to the PROC SQL statement.




SOURCE

data emp;
input emp $ dep $;
datalines;
Bill A
CQ A
Cora B
Peter B
Emma C
Nathan C
;
run;

%let DEP = work.dep;
data &DEP;
input dep $ dep_desc $;
datalines;
A Wasco
B Midland
C Lansing
;
quit;
run;

data hrs;
input emp $ hrs ;
datalines;
Bill 40
CQ 20
Cora 20
Peter 50
;
run;

proc sql noprint feedback;
select dep.dep, dep.dep_desc, sum(hrs.hrs) as hours
from dep, emp, hrs
where dep.dep = emp.dep
and emp.emp = hrs.emp
group by 1,2
;
quit;
run;


LOG

34   proc sql noprint feedback;
35   select dep.dep, dep.dep_desc, sum(hrs.hrs) as hours
36   from dep, emp, hrs
37   where dep.dep = emp.dep
38   and emp.emp = hrs.emp
39   group by 1,2
40   ;
NOTE: Statement transforms to:

        select DEP.dep, DEP.dep_desc, SUM(HRS.hrs) as hours
          from WORK.DEP, WORK.EMP, WORK.HRS
         where (DEP.dep = EMP.dep) and (EMP.emp = HRS.emp)
      group by 1, 2;

41   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.10 seconds
      cpu time            0.12 seconds


42   run;


Thursday, June 23, 2016

SAS: Negative times

If a time value is negative, it could lose the sign depending on the format you choose... Format timew. assumes time, whereas todw. assumes datetime.




data _null_ ;
   format __TIME TIME10. ;
   minutes = -23;
   __TIME = minutes * 60;
   format __TOD10 TOD10. ;
   __TOD10 = minutes * 60;
   __IN_MINUTES = intck( "MINUTES" , 0 , __TIME ) ;
   put _all_ ;
run;



Log

1    data _null_ ;
2       format __TIME TIME10. ;
3       minutes = -23;
4       __TIME = minutes * 60;
5       format __TOD10 TOD10. ;
6       __TOD10 = minutes * 60;
7       __IN_MINUTES = intck( "MINUTES" , 0 , __TIME ) ;
8       put _all_ ;
9    run;

__TIME=-0:23:00 minutes=-23 __TOD10=23:37:00 __IN_MINUTES=-23 _ERROR_=0 _N_=1
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.04 seconds