I would like to capture the status of data step or proc step in one variable. In order to do that first I'm trying to make use of the automatic macro variable &SYSRC.
In the below example (see line number 4851), there is a warning and so I would like to see the respective return code instead of 0 (indicates successful run without any warning/error). Am I doing something wrong?
4840 /*Solution Component Name derivation*/
4841 if find("&etls_jobName","_INPUT_",'_') > 0
4842 then SOLN_CMPNT_NM= "DATA IMPORT";
4843 else if find("&etls_jobName","_EXPORT_") > 0
4844 then SOLN_CMPNT_NM = "DATA EXPORT" ;
4845 else if find("&etls_jobName","_LOA_") > 0
4846 then SOLN_CMPNT_NM = "DATA LOADER" ;
4847 else if find("&etls_jobName","_TRA_") > 0
4848 then SOLN_CMPNT_NM = "DATA TRANSER" ;
4849 else SOLN_CMPNT_NM = "OTHER" ;
4850 /*Job return code*/
4851 %PUT &SYSRC.;
0
4852 run;
WARNING: In a call to the FIND function or routine, the modifier "_" not valid.
NOTE: There were 1 observations read from the data set WORK.VARS.
NOTE: The data set WORK.METADATA has 1 observations and 10 variables.
Why are you putting the vlaue of the macro variable before the data step has started running?
Your %PUT is displaying the value of SYSRC from before the data step has even been compiler.
Since the macro processor finishes with the code before it is passed to the compiler and so before the data step runs you ran this code:
%put &sysrc;
data ....;
...
run;
I ran the code as per your instruction but still I'm getting the return code as 0 for the program which had warning.
2097 %PUT &SYSRC;
0
2098 /*derive operationl metadata*/
2099 data metadata;
2100 set vars;
2101 /*Solution Component Name derivation*/
2102 if find("&etls_jobName","_INPUT_",'_') > 0
2103 then SOLN_CMPNT_NM= "DATA IMPORT";
2104 else if find("&etls_jobName","_EXPORT_") > 0
2105 then SOLN_CMPNT_NM = "DATA EXPORT" ;
2106 else if find("&etls_jobName","_LOA_") > 0
2107 then SOLN_CMPNT_NM = "DATA LOADER" ;
2108 else if find("&etls_jobName","_TRA_") > 0
2109 then SOLN_CMPNT_NM = "DATA TRANSER" ;
2110 else SOLN_CMPNT_NM = "OTHER" ;
2111 /*Job return code*/
2112 /*%PUT &SYSRC.;*/
2113 run;
WARNING: In a call to the FIND function or routine, the modifier "_" not valid.
NOTE: There were 1 observations read from the data set WORK.VARS.
NOTE: The data set WORK.METADATA has 1 observations and 10 variables
Why are you still writing the value from before the step.
What value does SYSRC have AFTER the data step is run?
Are you sure that DATA steps even change the value of SYSRC?
730 %let sysrc=0; 731 %put &=sysrc; SYsrc=0 732 data x; 733 This is not valid SAS code; ---- 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 734 run; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.X may be incomplete. When this step was stopped there were 0 observations and 0 variables. WARNING: Data set WORK.X was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 735 %put &sysrc; 0 736 737 %let sysrc=0; 738 %put &=sysrc; SYsrc=0 739 data x; 740 impossible=1/0; NOTE: Division by zero detected during the compilation phase, detected at line 740 column 14. 741 run; NOTE: The data set WORK.X has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 742 %put &sysrc; 0
SYSRC have value as 0 even after the data step has ran with warnings. Value is not changing even &sysrc is placed before,after or in the program. Could you please help me understand with one example?
I don't think that data steps change SYSRC. Try looking at SYSERR instead.
I think there is another new system option that will force SAS to treat WARNING message, like in your posted example, as ERROR messages. You might try that and see if it changes whether SYSERR is changed or not.
Even in your example value of &sysrc has not changed and it is suppose to change after the line number 735 in your log
@Babloo wrote:
I would like to capture the status of data step or proc step in one variable. In order to do that first I'm trying to make use of the automatic macro variable &SYSRC.
In the below example (see line number 4851), there is a warning and so I would like to see the respective return code instead of 0 (indicates successful run without any warning/error). Am I doing something wrong?
4840 /*Solution Component Name derivation*/ 4841 if find("&etls_jobName","_INPUT_",'_') > 0 4842 then SOLN_CMPNT_NM= "DATA IMPORT"; 4843 else if find("&etls_jobName","_EXPORT_") > 0 4844 then SOLN_CMPNT_NM = "DATA EXPORT" ; 4845 else if find("&etls_jobName","_LOA_") > 0 4846 then SOLN_CMPNT_NM = "DATA LOADER" ; 4847 else if find("&etls_jobName","_TRA_") > 0 4848 then SOLN_CMPNT_NM = "DATA TRANSER" ; 4849 else SOLN_CMPNT_NM = "OTHER" ; 4850 /*Job return code*/ 4851 %PUT &SYSRC.; 0 4852 run; WARNING: In a call to the FIND function or routine, the modifier "_" not valid. NOTE: There were 1 observations read from the data set WORK.VARS. NOTE: The data set WORK.METADATA has 1 observations and 10 variables.
Maxim 1: READ THE DOCUMENTATION!!!
&sysrc contains the return code of EXTERNAL(!) commands run by the x statement.
What you want to check is &syscc, which contains the current status of the SAS session itself.
I tried with &syscc as well but it still giving the value as 0 for the program which I posted in the Initial post.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.