Help using Base SAS procedures

data step

Reply
Contributor
Posts: 65

data step

I basically have a program that looks at WRS logs and SP logs.  In the code there are some checks to see if the file information is already in the permanent dataset.  When I run the code for the first time it wipes out all the SP information and if I rerun it the data for SP is there.  The problem is when there are no changes in the SP data.  My SET statement is setting to the temporary dataset with 0 records and is overriding the data.  My goal would be if there are no changes, don't touch the dataset and, if there are changes add them.

/*

Start of logging information for WRS.

*/

%DIRLISTWIN(\\blacktail\D$\SAS_93\BIPlatform\Lev2\Web\Logs,REPORT=N,REPORT1=N,SUBDIR=N);

LIBNAME sasdata BASE "D:\SAS_93\BIPlatform\Lev2\Data\SASData" ;

*ok;

DATA PortalReportLog;

  LENGTH FILENAME $100. report $200. Description $50.;

  format FILENAME $100. report $200.;

  SET SASDATA.PortalReportLog;

  WHERE Filename = "CreateEmptyDataset";

RUN;

DATA WRSKeyActionsFileList;

  set dirlist;

  FullPath = trimn(path) || '\' || trimn(filename);

  IF SUBSTR(filename,1,38) = 'SASWebReportStudio4.3_KeyActions.log_2';

  put path;

  put fullpath;

RUN;

%Macro doit(FullFileName, FileName);

  libname wrslog xml "&FullFileName";

  PROC DATASETS LIBRARY=WRSLOG;

  RUN;

  DATA EVENT;

    LENGTH FILENAME $100. report $200.;

    format report $200.;

    SET WRSLOG.EVENT;

    FILENAME = "&FileName";

  RUN;

proc append data=event base=PortalReportLog FORCE;

  run;

%Mend;

PROC SQL;

  CREATE TABLE ExistingFilelist AS

    SELECT DISTINCT FILENAME

    FROM SASDATA.PortalReportLog

    ORDER BY filename;

QUIT;

PROC SQL;

  CREATE TABLE CurrentFilelist AS

    SELECT DISTINCT FILENAME

    FROM WRSKeyActionsFileList

    ORDER BY filename;

QUIT;

PROC SQL;

  CREATE TABLE FilesToProcess AS

    SELECT A.FileName

    FROM CurrentFilelist A

    LEFT OUTER JOIN ExistingFilelist B

    ON A.FILENAME = B.FILENAME

    WHERE B.FILENAME IS NULL

    ORDER BY A.FileName;

QUIT;

DATA WRSKeyActionsFileList_1;

  MERGE WRSKeyActionsFileList(IN=inWRS)

      FilesToProcess(IN=inFTP);

  BY FileName;

  IF inWRS AND inFTP;

run;

filename cmds catalog 'work.temp.cmd.source';

data _null_;

  set WRSKeyActionsFileList_1;

  file cmds;

  put '%doit(' fullpath ' , ' filename ');';

run;

%include cmds;

DATA SASData.PortalReportLog;

    LENGTH Description $50. User $100.;

      length report $200.;

   SET PortalReportLog

    SASDATA.PortalReportLog;

RUN;

/*

start of SP logging

*/

%DIRLISTWIN(D:\sas_93\BIPlatform\Lev2\SASApp\StoredProcessServer\Logs,REPORT=N,REPORT1=N,SUBDIR=N);

DATA StoredProcessLogFileList;

  set dirlist;

  FullPath = trimn(path) || '\' || trimn(filename);

  IF SUBSTR(filename,1,16) = 'SASApp_STPServer';

RUN;

%Macro doit(FullFileName,FileName);

DATA WORK.IMPW;

  INFILE "&FullFileName"

    TRUNCOVER

    DSD

  ;

  LENGTH

    LogData $ 255

  ;

  INPUT

    @1 LogData  $255.

  ;

  LABEL

    LogData = "LogData"

  ;

RUN;

PROC SQL;

   CREATE TABLE WORK.QUERY_FOR_IMPW AS

   SELECT t1.LogData

      FROM WORK.IMPW AS t1

      WHERE t1.LogData CONTAINS 'Executing d:' OR t1.LogData CONTAINS 'Executing D:';

QUIT;

PROC SQL;

   CREATE TABLE WORK.SP_Usage_Table AS

   SELECT /* RunDate */

            (INPUT(substr(T1.LogData ,  6,5) || '-' || substr(T1.LogData ,1,4) ,MMDDYY10.)) FORMAT=MMDDYYD10. AS RunDate,

          /* RunTime */

            (INPUT(SUBSTR(t1.LogData,12,8),TIME.)) FORMAT=TIME8. AS RunTime,

          /* User */

            (SUBSTR(T1.LogData ,FINDC(T1.LogData ,':',20) + 1 ,

              FINDC(T1.LogData ,'@') - FINDC(T1.LogData ,':',  20)-1)) AS User length=100,

          /* Report */

            (substr(t1.LogData,findc(t1.LogData,':',-999)-1,199)) AS Report LENGTH=100,

          /* Description */

            ('Stored Process') AS Description

      FROM WORK.QUERY_FOR_IMPW AS t1;

QUIT;

DATA SP_Usage_Table;

  LENGTH FILENAME $100.;

  SET SP_Usage_Table;

  Filename="&Filename";

run;

proc append data=SP_Usage_Table base=SP_Usage_Log FORCE;

run;

%Mend;

filename cmds catalog 'work.temp.cmd.source';

proc sort data=StoredProcessLogFileList;

  by filename;

run;

PROC SQL;

  CREATE TABLE EXISTINGFILELIST AS

    SELECT DISTINCT FILENAME

    FROM SASData.DAWN_Report_Usage_Data

    ORDER BY FILENAME;

QUIT;

PROC SQL;

  CREATE TABLE CURRENTFILELIST AS

    SELECT DISTINCT FILENAME

    FROM StoredProcessLogFileList

    ORDER BY FILENAME;

QUIT;

PROC SQL;

  CREATE TABLE FilesToProcess AS

    SELECT A.FileName

    FROM CurrentFilelist A

    LEFT OUTER JOIN ExistingFilelist B

    ON A.FILENAME = B.FILENAME

    WHERE B.FILENAME IS NULL

    ORDER BY A.FileName;

QUIT;

DATA StoredProcessLogFileList_1;

  MERGE StoredProcessLogFileList(IN=inWRS)

      FilesToProcess(IN=inFTP);

  BY FileName;

  IF inWRS AND inFTP;

run;

data _null_;

  set StoredProcessLogFileList_1;

  file cmds;

  put '%doit(' fullpath ' , ' Filename ' );';

run;

%include cmds;

DATA SP_Temp;

  LENGTH Description $50. User $100.;

  SET SP_Usage_Log;

  Description = 'STP';

  JavaDate = .;

  Code = .;

  Report = Report;

  User = User;

  Date = RunDate;

  Time = RunTime;

  Drop StoredProcessName UserName RunDate RunTime LogData ProgramName;

RUN;

/*

this is where i am having the issue.  If there are no changes SP_Temp will be empty and will override all existing data

*/

DATA SASData.DAWN_Report_Usage_Data;

    LENGTH Description $50.User $100.;

  Set SASDATA.PortalReportLog SP_Temp;

RUN;

%macro z;

%global syscc;

%if (&syscc eq 4) %then %let syscc=0;

%if (&syscc eq 3000) %then %let syscc=0;

%if (&syscc eq 1012) %then %let syscc=0;

%mend;

%z;

%PUT &SYSCC;

RUN;

%PUT &SYSERR;

RUN;

Ask a Question
Discussion stats
  • 0 replies
  • 627 views
  • 0 likes
  • 1 in conversation