DATA Step, Macro, Functions and more

Check latest date in 3 different tables

Accepted Solution Solved
Reply
Super Contributor
Posts: 395
Accepted Solution

Check latest date in 3 different tables

Hi, what is the best way to check what the latest dates are in 3 differet tables from one procedure?  The vriable 'Process_Date' is called the same in all 3 tables, however there are no linkage between the 3 tables.. like acct. number.  Also is there a way to see the same ask, but if the term 'process_Date' is called different for all 3 tables?  Thanks.


Accepted Solutions
Solution
‎11-05-2016 03:00 PM
Super User
Posts: 6,955

Re: Check latest date in 3 different tables

data want (keep=max_date);
set
  table1
  table2
  table3
  end=done
;
retain max_date;
format max_date date9.;
max_date = max(max_date,process_date);
if done
then do;
  call symput('max_date',put(max_date,best.));
  output;
end;
run;

gives you both a dataset and a macro variable for further use.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 17,868

Re: Check latest date in 3 different tables

What are you expecting for output? 3 diff dates, highest from each?

One date that's highest from all three tables? 

Solution
‎11-05-2016 03:00 PM
Super User
Posts: 6,955

Re: Check latest date in 3 different tables

data want (keep=max_date);
set
  table1
  table2
  table3
  end=done
;
retain max_date;
format max_date date9.;
max_date = max(max_date,process_date);
if done
then do;
  call symput('max_date',put(max_date,best.));
  output;
end;
run;

gives you both a dataset and a macro variable for further use.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 6,955

Re: Check latest date in 3 different tables

If your date variable is called differently in the datasets, use the rename= dataset option to make it same.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 190 views
  • 0 likes
  • 3 in conversation