From: Anaconda on 22 Mar 2010 19:36 Hi, I am a bit confused why I get an empty dataset of SASLOG_EXTRACT below. The code can be pasted into the editor and submitted. data _null_; %global mvar_timestamp; day = date(); time = time(); sasdt = dhms(day, 0, 0, time); length chardate $10.; chardate = put(day, yymmdd10.); length charsasdt $16.; charsasdt = put(sasdt, datetime.); length macvar_timestamp $19.; macvar_timestamp = substr(chardate, 1, 4) || '_' || substr(chardate, 6, 2) || '_' || substr(chardate, 9, 2) || '_' || substr(charsasdt,9, 2) || '_' || substr(charsasdt,12, 2) || '_' || substr(charsasdt,15, 2) ; call symput('mvar_timestamp', macvar_timestamp); *Testing; put 'DAY:' day date9.; put 'TIME:' time time.; put 'SASDT:' sasdt datetime.; put 'CHARDATE:' chardate; put 'CHARSASDT:' charsasdate; put 'MACVAR_TIMESTAMP:' macvar_timestamp; %put MVAR_TIMESTAMP: &mvar_timestamp; run; %let new_logfile_sas = D:\Temp\SASLOG_&mvar_timestamp._comlete.log; %put NEW_LOGFILE_SAS = &new_logfile_sas; filename newlog "&new_logfile_sas"; proc printto log = newlog; run; /* Some code with errors */ data a; set sashelp.class; run; data b; /* Creating an error deliberately */ set sashelp.class#¤%&%; run; proc printto; run; /* Creating a complete dataset of the SAS log file */ data saslog_complete; infile "&new_logfile_sas" lrecl = 300 missover pad; length Linenr 8.; Linenr = _N_; input @1 Logtext $250. ; run; /* I don't understand why I get 0 observations in the dataset SASLOG_EXTRACT below. I would have expected the one record in linenr. 31 in the SAS log. So why not? */ data saslog_extract; length Type $20.; length Language_Component $15.; Type = " "; Language_Component = " "; set saslog_complete; if substr(Logtext,1, 5) eq "WARNING" and ( index(Logtext, "The data set") > 0 and index(Logtext, "may be incomplete.") > 0 and index(Logtext, "When this step was stopped there were") > 0 and index(Logtext, "observations and") > 0 and index(Logtext, "variables.") > 0 ) then do; Type = "WARNING"; Language_Component = "SAS language"; output; end; run; Does anyone see what is wrong with my code? - Anaconda
From: Tom Abernathy on 22 Mar 2010 23:37 Here is one obvious problem line: if substr(Logtext,1, 5) eq "WARNING" and .... The first five characters cannot equal a seven letter word. Note it is easier to use the : modifier on the = operator than use the SUBSTR function. if logtext =: 'WARNING' .... On Mar 22, 7:36 pm, Anaconda <r...(a)fastlane.no> wrote: > Hi, > > I am a bit confused why I get an empty dataset of SASLOG_EXTRACT > below. > The code can be pasted into the editor and submitted. > > data _null_; > %global mvar_timestamp; > day = date(); > time = time(); > sasdt = dhms(day, 0, 0, time); > length chardate $10.; > chardate = put(day, yymmdd10.); > length charsasdt $16.; > charsasdt = put(sasdt, datetime.); > length macvar_timestamp $19.; > macvar_timestamp = substr(chardate, 1, 4) || '_' || > substr(chardate, 6, 2) || '_' || > substr(chardate, 9, 2) || '_' || > substr(charsasdt,9, 2) || '_' || > substr(charsasdt,12, 2) || '_' || > substr(charsasdt,15, 2) > ; > call symput('mvar_timestamp', macvar_timestamp); > *Testing; > put 'DAY:' day date9.; > put 'TIME:' time time.; > put 'SASDT:' sasdt datetime.; > put 'CHARDATE:' chardate; > put 'CHARSASDT:' charsasdate; > put 'MACVAR_TIMESTAMP:' macvar_timestamp; > %put MVAR_TIMESTAMP: &mvar_timestamp; > run; > > %let new_logfile_sas = D:\Temp\SASLOG_&mvar_timestamp._comlete.log; > %put NEW_LOGFILE_SAS = &new_logfile_sas; > filename newlog "&new_logfile_sas"; > > proc printto log = newlog; > run; > > /* Some code with errors */ > data a; > set sashelp.class; > run; > > data b; > /* Creating an error deliberately */ > set sashelp.class#¤%&%; > run; > > proc printto; > run; > > /* Creating a complete dataset of the SAS log file */ > data saslog_complete; > infile "&new_logfile_sas" lrecl = 300 missover pad; > length Linenr 8.; > Linenr = _N_; > input @1 Logtext $250. ; > run; > > /* > I don't understand why I get 0 observations in the dataset > SASLOG_EXTRACT below. > I would have expected the one record in linenr. 31 in the SAS log. > So why not? > */ > data saslog_extract; > length Type $20.; > length Language_Component $15.; > Type = " "; > Language_Component = " "; > set saslog_complete; > if substr(Logtext,1, 5) eq "WARNING" and > ( index(Logtext, "The data > set") > 0 and > index(Logtext, "may be > incomplete.") > 0 and > index(Logtext, "When this step was stopped there > were") > 0 and > index(Logtext, "observations > and") > 0 and > index(Logtext, > "variables.") > 0 > ) > then do; > Type = "WARNING"; > Language_Component = "SAS language"; > output; > end; > > run; > > Does anyone see what is wrong with my code? > > - Anaconda
From: data _null_; on 23 Mar 2010 07:32 On Mar 22, 6:36 pm, Anaconda <r...(a)fastlane.no> wrote: > data _null_; > %global mvar_timestamp; > day = date(); > time = time(); > sasdt = dhms(day, 0, 0, time); > length chardate $10.; > chardate = put(day, yymmdd10.); > length charsasdt $16.; > charsasdt = put(sasdt, datetime.); > length macvar_timestamp $19.; > macvar_timestamp = substr(chardate, 1, 4) || '_' || > substr(chardate, 6, 2) || '_' || > substr(chardate, 9, 2) || '_' || > substr(charsasdt,9, 2) || '_' || > substr(charsasdt,12, 2) || '_' || > substr(charsasdt,15, 2) > ; > call symput('mvar_timestamp', macvar_timestamp); > *Testing; > put 'DAY:' day date9.; > put 'TIME:' time time.; > put 'SASDT:' sasdt datetime.; > put 'CHARDATE:' chardate; > put 'CHARSASDT:' charsasdate; > put 'MACVAR_TIMESTAMP:' macvar_timestamp; > %put MVAR_TIMESTAMP: &mvar_timestamp; > run; I would replace this entire data step with.... %let timestamp = %sysfunc(translate(%sysfunc(datetime(),is8601dt.),_,:)); 2148 %put NOTE: TIMESTAMP=×tamp; NOTE: TIMESTAMP=2010-03-23T06_29_18 This timestamp can be read with YMDDTTM informat.
|
Pages: 1 Prev: univariate default tables Next: Multilevel Analysis SAS code..HELP needed |