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

Hi,

I have two datasets about a group of patients. In the first dataset, called medhis, I have the medical history of patients which includes the dates when a lab or radiology test was ordered for a patient. Something like this:

patientID     Result     Date

001             lab          05/04/2010

001             lab          06/07/2011

001             rad          07/07/2012

002             lab          05/02/2010

.                 .

... more data lines ......        

.                 .                 

205             rad          08/21/2015

 

In the second dataset, called consent, I have the dates and types of patient consent, but the structure is different. Something like the following. Note that the data from a patient only appears in one row and not all patients provide multiple consents 

 

patientID    Consnet1    Date1              Consent2    Date2             Consent3    Date3

001             Y        06/04/2010         N           08/08/2012         .          .

002             Y        08/05/2011         .           .

.               .

... more data lines ......        

.               .  

205             N       08/21/2015

 

I want to create a table in with a structure like the medhis table with a variable called totdoc which shows the total number medical records that are ordered for each patient from the beginning until each consent date. something like this:

patientID     ConsentType    ConsentDate      totdoc

001             Y            06/04/2010        1

001             N            08/08/2012        3 

002             Y            08/05/2011        1

.                .

... more data lines ......        

.                .                 

205             N             08/21/2015       1

 

I think I somehow should use arrays within a proc sql, but I don't know how. 

I appreciate your help in advance

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You need both, but not together :

 

data consentList;
set consent;
array d{*} date:;
array c{*} consent:;
do i = 1 to dim(d);
	consentType = c{i};
	consentDate =  d{i};
	if not missing(consentDate) then output;
	end;
drop i;
run;

proc sql;
create table want as
select patientID, consentType, consentDate, 
	(select count(*) from medhis where patientID=a.patientID and date <= a.consentDate) as totDoc
from consentList as a;
quit;

(untested)

PG

View solution in original post

3 REPLIES 3
Reeza
Super User

Arrays don't exist within Proc SQL, I think you're looking for a transpose, via a datastep and array.

 

Here's a reference that goes through several examples of transposing via a data step.

http://www.ats.ucla.edu/stat/sas/modules/widetolong_data.htm

PGStats
Opal | Level 21

You need both, but not together :

 

data consentList;
set consent;
array d{*} date:;
array c{*} consent:;
do i = 1 to dim(d);
	consentType = c{i};
	consentDate =  d{i};
	if not missing(consentDate) then output;
	end;
drop i;
run;

proc sql;
create table want as
select patientID, consentType, consentDate, 
	(select count(*) from medhis where patientID=a.patientID and date <= a.consentDate) as totDoc
from consentList as a;
quit;

(untested)

PG
niam
Quartz | Level 8

This works! Thank you very much

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 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
  • 1470 views
  • 0 likes
  • 3 in conversation