When there are multiple datasets in a sas library, I want to pick the latest date for that id from all the datasets and to know which particular dataset that date is coming from.
example below
let us assume I have three datasets in library name source like
source.ae, source.cm, source.pr.
In each dataset for id 1 I have date variables.
I want to club all the dates for the id into 1 dataset and pick the latest date record and know which particular dataset it is coming from.
Have:
AE data
id date datapagename
1 01/01/2019 AE
CM data
id date datapagename
1 01/02/2019 CM
PR data
id date datapagename
1 01/03/2019 PR
Want :
final dataset:
id date datapagename last date flag
1 01/01/2019 AE
1 01/02/2019 CM
1 01/03/2019 PR Y
Thanks
Raj
How big are these data sets? Is efficiency required?
If not, just stack them and take the latest record per ID.
@yashraj89 wrote:
When there are multiple datasets in a sas library, I want to pick the latest date for that id from all the datasets and to know which particular dataset that date is coming from.
example below
let us assume I have three datasets in library name source likesource.ae, source.cm, source.pr.
In each dataset for id 1 I have date variables.
I want to club all the dates for the id into 1 dataset and pick the latest date record and know which particular dataset it is coming from.
Have:
AE data
id date datapagename
1 01/01/2019 AE
CM data
id date datapagename
1 01/02/2019 CM
PR data
id date datapagename
1 01/03/2019 PR
Want :
final dataset:
id date datapagename last date flag
1 01/01/2019 AE
1 01/02/2019 CM
1 01/03/2019 PR Y
Thanks
Raj
Data want;
Length dsn source $50.;
Set ab bc pr Indsname=source;
Dsn=source;
Run;
Proc sort data= want;
By ID descending date;
Run;
Data flagged;
Set want;
By id;
If first.Id then flag =1;
Run;
Proc sort data = want nodupkey out=max;
By Id;
Run;
@yashraj89 wrote:
Below is just an example there are 50 -100 datasets in the library
So is your next question how to get a list of all data sets in a library?
If you have a naming convention try some of the options here:
Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.