BookmarkSubscribeRSS Feed
sd_ncsu
Calcite | Level 5

Hi. I have data over time that contains the day someone initiated care (StartDate, DATE9.), how long they received care during that encounter (days_in_care, Num type), and the corresponding diagnosis for that visit (dx_1, Num type and the value is either 1 or 0 since only 1 diagnosis is tracked given the patient population). I've created two files ('same' contains everyone with the same diagnosis over time, 'not_same' contains everyone with diagnoses that change over time). I am interested in exploring patterns of how the diagnosis variable changes. Beyond the variables above, the ID is a character variable, and the data are arrayed in a long file--one row per encounter (the most encounters in the 'not_same' file for any individual is 40 and there are ~90 people in the dataset). I am struggling to implement code that:

  1. effectively displays the various visual patterns of 0s and 1s over time in 'not_same', including how many different pattern 'types' there are. For example, some data patterns will look like 0,0,0,0,1,1,1,1,1 and others will look like 1,1,1,0,1,0, etc. Any advice on ways to display multiple patterns of data?
  2. then counts and sums the number of visits and days until a diagnosis changes from 0 to 1 (i.e., want_lag_days and want_lag_encounters). 

Sample data:

ID (character)StartDate (DATE9.)dx_1 (numeric, 0/1)days_in_care (numeric, ranges from 0, released in under 24 hours to 352)want_lag_dayswant_lag_encounters
ff52fc4315ddb11Sep2016015162
ff52fc4315ddb18Nov201601162
ff52fc4315ddb19Dec20161217162
ff52fc4315ddb16Aug201717162
593f1e8e261516Jul201501741793
593f1e8e26159Jan2018011793
593f1e8e26159Nov2018041793
593f1e8e26158Apr2019171793
 
Thank you for any suggestions!
1 REPLY 1
JOL
SAS Employee JOL
SAS Employee

Have your tried transposing the data into a wide structured table as starting point? Based on sample data provided:

/* Sort data by id first, so by can be used in PROC Transpose */

PROC SORT DATA=WORK.BOOK1 OUT=SORT_BOOK1;
BY ID;
RUN;

 

/* Transpose data so date form the new columns, added a prefix of D_ to create valid column names */

PROC TRANSPOSE DATA=SORT_BOOK1
OUT=WORK.TRNS_BOOK1(DROP=_NAME_)
PREFIX=D_;
BY ID;
ID StartDate;
VAR dx_1;
RUN;

 

/* Use the Data Step to convert numeric columns to character  and concatenate*/

DATA NEW;
SET WORK.TRNS_BOOK1;
ARRAY D{8} _NUMERIC_;
ARRAY CDATE{8} $;
DO I = 1 TO 8;
CDATE(I) = PUT(D(I),3.);

IF CDATE(I)=. THEN
CDATE(I)='';
END;
PATTERN = CATX(',', OF CDATE1-CDATE8);
KEEP CDATE1-CDATE8 PATTERN;
RUN;

 

/* Create list report */

PROC PRINT DATA=NEW;
RUN;

 

Result

JOL_0-1654633718557.png

 

 

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
  • 1 reply
  • 406 views
  • 0 likes
  • 2 in conversation