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

Hi SAS community,

 

 I have 4 datasets that have data on same population across 6 time points.

 

I want to know how to perform the occurrence as show below.

 

Dataset 1

 

ID       Var 1

1           0

2           0

3           0

4           0

5           0

 

Dataset 2

 

ID       Var 1

1           0

2           0

3           1

4           0

5            0

 

Dataset 3

 

ID       Var 1

1           1

2           0

3           1

4           0

5           0

 

Dataset 4

 

ID       Var 1

1           1

2           0

3           0

4           1

5           0

 

I want to find of all the people who had an occurrence of 1 at-least once across the 4 time points or Datasets. 

1 ACCEPTED SOLUTION

Accepted Solutions
morgalr
Obsidian | Level 7

I would merge all of the datasets, then use SQL.

 

proc sql;
  create table mergedSet as select * from Dataset1;
  insert into mergedSet values(select * from Dataset2);
  insert into mergedSet values(select * from Dataset3);
  insert into mergedSet values(select * from Dataset4);
  insert into mergedSet values(select * from Dataset5);

  select id, sum(var1)>0 as hasValue from mergedSet 
  group by id;
quit;

View solution in original post

2 REPLIES 2
morgalr
Obsidian | Level 7

I would merge all of the datasets, then use SQL.

 

proc sql;
  create table mergedSet as select * from Dataset1;
  insert into mergedSet values(select * from Dataset2);
  insert into mergedSet values(select * from Dataset3);
  insert into mergedSet values(select * from Dataset4);
  insert into mergedSet values(select * from Dataset5);

  select id, sum(var1)>0 as hasValue from mergedSet 
  group by id;
quit;
Astounding
PROC Star

A data step approach:

 

data want;

set dataset1 dataset2 dataset3 dataset4;

by ID;

where var1=1;

if first.ID;

keep ID;

run;

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 997 views
  • 1 like
  • 3 in conversation