BookmarkSubscribeRSS Feed
yashraj89
Obsidian | Level 7

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

 

3 REPLIES 3
Reeza
Super User

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 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

 


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
Obsidian | Level 7
Below is just an example there are 50 -100 datasets in the library
Reeza
Super User

@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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 685 views
  • 0 likes
  • 2 in conversation