BookmarkSubscribeRSS Feed
maxy
Calcite | Level 5

My dataset looks like below:

```

ID  Date_of_infusion1  Date_of_infusion2...Date_of_infusion33  Labdate1   Labdate2  ...Labdate100
A     04/01/2016            08/06/2016               .         11/08/2017  10/21/2017      .
B     09/18/2015                .                    .         09/22/2015  09/30/2015      .
C     11/24/2015                .                    .         07/05/2015      .           .

 ```

What I want to do: For each ID, if the labdate is after any of the infusion dates but within 4 months of that date(any infusiondate<=labdate<=the infusiondate+4months), then keep it; otherwise drop the labdate.

What I was trying to do: make 2 arrays,one for infusion dates one for labdates. Then create a "flag" variable associated with Labdate.

I wrote something like this:

array infusion {*} date_of_infusion:;
array labdate {*} labdate:;
array flag {101} flag0-flag100;

do i= 1 to dim(labdate);
    do j=1 to dim(infusion);
    if infusion[j] ne . and infusion[j]<=labdate[i]<=intnx('month',infusion[j],4) then flag[i]=1;else flag[i]=0;
    end;
end; 

However, the result doesn't look like something I want...

Any help is appreciated! Thanks!

3 REPLIES 3
r_behata
Barite | Level 11

Assuming Each Flag variable corresponds to a Labdate.

 

data want;
	set have;
	array infusion {*} date_of_infusion:;
	array labdate {*} labdate:;
	array flag {101} flag0-flag100;


		do i= 1 to dim(labdate);
			do j=1 to dim(infusion);
				if infusion[j] ne . and infusion[j]< labdate[i]<=intnx('month',infusion[j],4) then
					do;
						flag[i]=1;
						leave;
					end;
				else flag[i]=0;
			end;
		end;
run;
ChrisNZ
Tourmaline | Level 20

> otherwise drop the labdate

What does this mean? You can't drop a column.

 

andreas_lds
Jade | Level 19

Please:

  • post data in usable form
  • post the expected result with the data you  have posted
  • reduce the data, so that is only shows all cases you have/expect

Have you thought about normalizing the data? Having numbered columns is almost always a sign for bad data-design. In your case having two tables, one with ID and one infusion_date and the other table with ID and one labdate, maybe a sql-merge could solve the problem.

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!

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
  • 346 views
  • 3 likes
  • 4 in conversation