Hello,
I have a scheduled job that keeps on failing.
The SAS runs fine except for a it gets WARNING: Character expression will be truncated when assigned to character column Type.
I was told by our support to configure the scheduler to look for exit code 1 since the SAS tables are being updated as expected. However, if I change this to exit code 1, it won’t be able to detect if the code has an error or if it failed.
Asking the scheduler to look for Exit Code = 0, fails because I have a Warning message.
My questions are:
Here is my sas code, it’s very simple but I noticed that the job is failing when add the insert code.
Really appreciate your help here.
proc import out=work.import
datafile='directory/a.xls'
dbms=xls replace ;
getnames=yes;
run;
proc sql;
insert into server.final (Date, Name, Type, Full_Comments)
select
a.Date,
a.Name,
a.Type,
a.Full_Comments
from work.import a;
quit;
%put &=syscc;
With regard to your 2nd question (exit code) ... I would use &syserr.
Macro Language Reference
SYSCC Automatic Macro Variable
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p11nt7mv7k9hl4n1x9zwkralgq1b.htm
Macro Language Reference
SYSERR Automatic Macro Variable
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1wrevo4roqsnxn1fbd9yezxvv9k.htm
data want;
set notfound;
run;
proc options option=errorcheck; run;
%put &=Syscc;
%put &=SysErr;
%put &=SysWarningText;
%put &=SysErrorText;
/* end of program */
Koen
With regard to your 2nd question (exit code) ... I would use &syserr.
Macro Language Reference
SYSCC Automatic Macro Variable
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p11nt7mv7k9hl4n1x9zwkralgq1b.htm
Macro Language Reference
SYSERR Automatic Macro Variable
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1wrevo4roqsnxn1fbd9yezxvv9k.htm
data want;
set notfound;
run;
proc options option=errorcheck; run;
%put &=Syscc;
%put &=SysErr;
%put &=SysWarningText;
%put &=SysErrorText;
/* end of program */
Koen
Thanks a bunch @sbxkoenk this is exactly what I'm looking for!
%put &=SysErr;
I consider it best practice to fix the cause of the warning rather than fixing the symptoms. Try this:
proc sql;
insert into server.final (Date, Name, Type, Full_Comments)
select
a.Date,
a.Name,
a.Type as Type length = 15,
a.Full_Comments
from work.import a;
quit;
@SASKiwi thank you very much, really appreciate the advice!
I'm very much for an approach where SAS code shouldn't return warnings. I believe a warning creates an exit code 1 but an error exit code 2. If you would allow for exit code 1 you still would capture error conditions.
Excel is just a bad data source for any sort of ETL style process. You can't rely on getting stable results/table structures using Proc Import. The result will always depend on the specific version of the Excel and what data it contains.
My first question would be: Why do you get a variable with a length longer than expected by your target table? Proc Import creates the length of a character variable using the longest string it finds in the data so likely the Warning is an indication for actual string truncation.
Also important: With the xls engine you need to define guessingrows=max as else string truncation can already occur during import with Proc Import.
@Patrick I tried to configure the scheduler to look for exit code = 1 after the code ran after deliberately screwing up my code i.e missing ";" but the scheduler didn't detect that error and still ended with Success status.
As for why I'm using excel, this is actually someone else's task, I'm just trying to automate it without really changing the work file of that person because he didn't know how to code in SAS. Adding guessingrows=max is really helpful, I should have thought of that right away! But really appreciate that feedback!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.