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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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