I doing like this
libname DZY 'Path';
Proc sql;
select * from DZ.some_table;
run;
Here I have to add an error handling like if something goes wrong in select statement or within the block I have to write error message to an separate text file in the folder. This is what I tried
%macro sortclass;
Proc sql;
select * from DZ.some_table;
run;
%if &SQLRC gt 0 %then %goto error;
%error:
proc export data=""
run;
%exit:
%mend;
%sortclass;
I am trying to do an try catch like error handling.., How can do this in effective way. Thanks In advance
You should not do this, because you have to re-invent what the sas interpreter already does: checking the syntax of your code.
Why? You can check the existence of dataset, which is something that maybe necessary. However with such simple code you should not need to check? This:
%macro sortclass;
Sounds to me like your trying to re-write SAS functionality which is both a waste of time, and less stable.
@Pradeepbanu wrote:
I doing like this
libname DZY 'Path'; Proc sql; select * from DZ.some_table; run;
Here I have to add an error handling like if something goes wrong in select statement or within the block I have to write error message to an separate text file in the folder. This is what I tried
%macro sortclass; Proc sql; select * from DZ.some_table; run; %if &SQLRC gt 0 %then %goto error; %error: proc export data="" run; %exit: %mend; %sortclass;
I am trying to do an try catch like error handling.., How can do this in effective way. Thanks In advance
Your proc export is going to throw an error as you are missing ; and you are missing an OUTFILE option.
Since %exit is not referenced that will generate errors in the log. Also since you do not have anything that skips your proc export it will execute every time. See this code for examples:
Wrong as it output the value regardless of the value of the test.
%macro dummy(value); %if &value= 3 %then %goto error; %error: %Put the value of value is &value; %mend; %dummy(3); %dummy(5);
Marginally better as only has the output when the test is true:
%macro dummy2(value); %if &value=3 %then %goto error; %else %goto exit; %error: %Put the value of value is &value; %exit: %mend; %dummy2(3); %dummy2(5);
Thanks this is an excellent solution.., I have a question in writing file??
libname DZ 'Dataset';
%macro dummy2(value);
proc sql;
select * from DZ.HighV_Trans /* misspelled */
run;
%if &value=3 %then %goto error;
%else %goto exit;
%error:
/* here how do I write error in this file?? */
proc export data = ??
outfile ="C/Pradeep/Log.txt"
/*dbms = csv replace;*/
run;
%Put the value of value is &value;
%exit:
%mend;
%dummy2(3);
%dummy2(5);
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.