Many thanks for your help. These are my answers: Does your data set have only one row? Yes just one row as below: my dataset called JORQUEC.TEST has just one row with 3 variables: ID maxmargin_dt maxmodelmart_d 1 30JUN2019 359 Your If condition would evaluate for multiple lines of your data so it's possible that some will be true and some will be false? No it will evaluate just one line. What version of SAS do you have? 9.4 Is this block of code within a macro already? yes How much do you know about macros? almost nothing I am struggling with this . Is there a reason you have a file with an extension of CSV with & as the delimiter? No it could be any kind of file . Let me clarify better my objective: Step1: I check two diferent tables and extract the maximum date from those, with this information save a data set Jorquec.test Step2: Step3: ( most difficult for me) I need to check if those dates maxmargin_dt is equal to previous month ( a macro month that I called ONEDT2 , I really dont know if it is correct ) and maxmodelmart_d is different from ( a macro called monthid), if both conditions are true then create a file that could be an empty file as well as I just need to create this file because this would be my trigger for another process. Does it make sense now for you? /*-----------------SAS CODE ------------------*/ %let today=%sysfunc(today()); %let currdt=%sysfunc(datetime()); %let month_id = %str(%')&MONTHID1.%str(%');/*'340';*/ data _null_; date2=intnx("month",&today.,-1,'end'); call symput('ONEDT2',"1"||substr(put(date2,DDMMYYN.),7,2)||substr(put(date2,DDMMYYN.),3,2)||substr(put(date2,DDMMYYN.),1,2)); %put &ONEDT2.; mthid1=intck('month','01jan1990'd,&today.)+1-1; call symput('MONTHID1',put(mthid1,3.)); %put &MONTHID1.; run; /*STEP 1 */ Proc SQL; connect to teradata (user=&teradata_user. password=&teradata_pwd. server = 'edwprod' database = 'nuc_pl_user_view'); Create table JORQUEC.TEST as select * from connection to teradata( select a.ID, a.maxmargin_dt, b.maxmodelmart_d from ( select 1 as ID, max(month_end_dt) as maxmargin_dt from nuc_pl_user_view.pg_margin_stack) as A left join ( select 1 as ID, max(month_id) as maxmodelmart_d from Insights_rm.Consumer_Model_Mart) as B on a.ID = b.ID ); disconnect from teradata ; QUIT; /* STEP 2 */ DATA JORQUEC.TEST2; SET JORQUEC.TEST; IF (maxmargin_dt = &ONEDT2.) and (maxmodelmart_d <> &month_id.) then do; end; /* STEP 3 - PROC EXPORT -*/ PROC EXPORT DATA=JORQUEC.TEST OUTFILE='//SASCommon/jorquec/TRIGGER_PAYGO.CSV' DBMS=dlm REPLACE; delimiter='&'; RUN;
... View more