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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 1495 views
  • 1 like
  • 3 in conversation