BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
amol123
Fluorite | Level 6

Dear All, 

 

Please refer below code:

 

Precode -
%let start_time=%sysfunc(datetime());
 
Postcode - 
 
 
%let end_time = %qsysfunc(datetime());

%let to_date=%sysfunc(today(),date9.);
%put &to_date.;
proc sql;
select max(datepart(start_time)) format =date9.
into :date from target.test_control where job_name='ch_1';
run;
%put &date.;
 


proc sql;
select max(datepart(start_time))
format = date9. into :up_time from target.test_control where job_name='ch_1';
run;
%put &up_time.;


%let today_dt=%sysfunc(datepart(%sysfunc(datetime())),date9.);
%put &today_dt.;
 
%macro execute;
%if &up_time.= &today_dt. 
%then %do;
proc sql;
update target.test_control
set start_time=&start_time.,
end_time=&end_time.,
last_update_time=&end_time.,
status ='Y'
where job_name='ch_1' and &date.=&to_date.;
run;
%end;
%else %do;
proc sql;
insert into target.test_control values('flow_1',"&etls_jobname.",&start_time.,&end_time.,&end_time.,'sasdemo','Y');
run;
%end;
%mend;
%execute;

 

I am trying to update only new inserted(today's) observation in test_control table where max date of test_control table equal to today.

Scenario :

Trying to update few columns in test_control table based on two date macro variables which is created in above postcode section.
variable names and condition = &date.=&to_date. , While executing this code it return below error message.

date macro variable contains maximum updated date in control table and to_date variable contains system date, so i just want to update the observation where these two dates has equal value(todays date value).

Please refer "where" condition in macro.



Error Log -

184 07JAN2019
_______
22
76
MPRINT(EXECUTE): update target.test_control set start_time=1862501204.91143, end_time=1862501204.93361,
last_update_time=1862501204.93361, status ='Y' where job_name='ch_1' and 07JAN2019=07JAN2019;
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, EQT, GE, GET,
GT, GTT, LE, LET, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.


Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
amol123
Fluorite | Level 6

Hi 

 

----------precode----------
%let start_time=%sysfunc(datetime());

----------postcode--------------
%let end_time = %qsysfunc(datetime());


%let to_date=&sysdate.;
%put &to_date.;


proc sql;
select max(datepart(start_time)) format =date7.
 into :date1 from target.job_control where job_name="&etls_jobname.";
run;
%put &date1.;






proc sql;
select max(datepart(start_time)) format =date7.
 into :up_time1 from target.job_control where job_name="&etls_jobname.";
run;
%put &up_time1.;






/*%put dt=%sysfunc(datepart(%sysfunc(datetime())));*/
/*%let today_dt1=%sysfunc(datepart(%sysfunc(datetime())));*/
%let today_dt1=&sysdate;
%put &today_dt1.;

data aa;
todate=put(today(),best.);
call symput ('today_dt',todate);
run;

%put &today_dt.;


%macro execute;
%if  "&up_time1"d = "&today_dt1"d 
%then %do;
proc sql;
update  target.job_control
set start_time=&start_time.,
 end_time=&end_time.,
 status ='Y'
/*where  "&date1"d="&to_date"d and  job_name='ch_1' and status='N';*/
where  datepart(start_time)=%sysfunc(today()) and  job_name="&etls_jobname.";
run;
%end;      

%else %do;

proc sql;
insert into target.job_control values('Dashboard1',"&etls_jobname.",&start_time.,&end_time.,'sasdemo','Y');
run;
%end;
%mend;
%execute;



Once again thank you for your valuable time.

 

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

 

Your title says "Date macro variable not resolved". Where does that wording come from?

 

Show us the entire SASLOG related to this code you are running. Click on the {i} icon and paste it into the window that opens.

--
Paige Miller
amol123
Fluorite | Level 6

Hi 

 

----------precode----------
%let start_time=%sysfunc(datetime());

----------postcode--------------
%let end_time = %qsysfunc(datetime());


%let to_date=&sysdate.;
%put &to_date.;


proc sql;
select max(datepart(start_time)) format =date7.
 into :date1 from target.job_control where job_name="&etls_jobname.";
run;
%put &date1.;






proc sql;
select max(datepart(start_time)) format =date7.
 into :up_time1 from target.job_control where job_name="&etls_jobname.";
run;
%put &up_time1.;






/*%put dt=%sysfunc(datepart(%sysfunc(datetime())));*/
/*%let today_dt1=%sysfunc(datepart(%sysfunc(datetime())));*/
%let today_dt1=&sysdate;
%put &today_dt1.;

data aa;
todate=put(today(),best.);
call symput ('today_dt',todate);
run;

%put &today_dt.;


%macro execute;
%if  "&up_time1"d = "&today_dt1"d 
%then %do;
proc sql;
update  target.job_control
set start_time=&start_time.,
 end_time=&end_time.,
 status ='Y'
/*where  "&date1"d="&to_date"d and  job_name='ch_1' and status='N';*/
where  datepart(start_time)=%sysfunc(today()) and  job_name="&etls_jobname.";
run;
%end;      

%else %do;

proc sql;
insert into target.job_control values('Dashboard1',"&etls_jobname.",&start_time.,&end_time.,'sasdemo','Y');
run;
%end;
%mend;
%execute;



Once again thank you for your valuable time.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2343 views
  • 1 like
  • 3 in conversation