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

Hello, 

 

I have a dataset with the following structure. 

 

exposure dataset structure.JPG

 

What I want to do is keep only those observations with a day_01 to day_05 value of "1" for any day between the exposure_start and exposure_end.

 

I would like to do this for each Participant_ID. The exposure_start and exposure_end values are unique to each participant_id

 

Any ideas? 

 

Here is the code for this sample dataset:

data have;
	input WELL_ID DAY_01 DAY_02 DAY_03 DAY_04 DAY_05 EXPOSURE_START $ EXPOSURE_END $ PARTICIPANT_ID;
	FORMAT WELL_ID z14.;
	datalines;
		01133244410000 0 0 1 0 0 DAY_01 DAY_05 1
		02019220960000 0 0 0 0 0 DAY_01 DAY_05 1
		07167297020000 1 0 0 0 0 DAY_01 DAY_05 1
		17067210480000 0 0 0 0 0 DAY_01 DAY_05 1
		34000000000000 0 0 0 0 0 DAY_01 DAY_05 1
		34001200010000 0 0 0 0 0 DAY_02 DAY_04 2
		34001200020000 0 0 0 0 0 DAY_02 DAY_04 2
		34001200030000 0 0 0 1 0 DAY_02 DAY_04 2
		34001200040000 0 0 0 0 0 DAY_02 DAY_04 2
		34001200050000 0 0 0 0 0 DAY_02 DAY_04 2
	;
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
	set have;
	array d(*) day_01-day_05;
	exp_start=input(scan(exposure_start,2,'_'),2.);
	exp_end=input(scan(exposure_end,2,'_'),2.);
	do i=exp_start to exp_end;
	    if d(i)=1 then do; 
			output; 
			leave;
		end;
	end;
	drop i;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data want;
	set have;
	array d(*) day_01-day_05;
	exp_start=input(scan(exposure_start,2,'_'),2.);
	exp_end=input(scan(exposure_end,2,'_'),2.);
	do i=exp_start to exp_end;
	    if d(i)=1 then do; 
			output; 
			leave;
		end;
	end;
	drop i;
run;
--
Paige Miller
JJ_83
Obsidian | Level 7

Wow, this works perfectly! Thank you so much!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 467 views
  • 1 like
  • 2 in conversation