Hello,
I have a dataset that has lab draws over the span of a few days (example below). I want to create a dataset that has a unique line for each patient, with variables iterating _1, _2, etc. for each draw. I have tried to use an array, but am not very experienced with them so any help is much appreciated.
Thanks!
Dataset I currently have:
Patient | ALT | AST | INR |
1 | 20 | 24 | 1.01 |
1 | 33 | 48 | 1.03 |
2 | 15 | 30 | 1.11 |
2 | 17 | 32 | 1.25 |
2 | 18 | 33 | 1.30 |
Dataset I want to have:
Patient | alt_1 | ast_1 | inr_1 | alt_2 | ast_2 | inr_2 | alt_3 | ast_3 | inr_3 |
1 | 20 | 24 | 1.01 | 33 | 48 | 1.03 | . | . | . |
2 | 15 | 30 | 1.11 | 17 | 32 | 1.25 | 18 | 33 | 1.30 |
Thanks again!
data have;
input Patient ALT AST INR;
cards;
1 20 24 1.01
1 33 48 1.03
2 15 30 1.11
2 17 32 1.25
2 18 33 1.30
;
data temp;
set have;
by Patient;
if first.Patient then n=0;
n+1;
run;
proc transpose data=temp out=temp2;
by Patient n;
var ALT AST INR ;
run;
proc transpose data=temp2 out=want(drop=_NAME_) delimiter=_;
by Patient ;
id _NAME_ n;
var col1;
run;
Usually, turning a long data set to a wide data set is a poor choice, and harder to handle.
What analysis/table/report are you trying to create with this data?
I completely agree. I am just adjusting the data to fit into a historic database that was created long before I was working on it, so to fit it in I unfortunately need to make it wide.
data have;
input Patient ALT AST INR;
cards;
1 20 24 1.01
1 33 48 1.03
2 15 30 1.11
2 17 32 1.25
2 18 33 1.30
;
data temp;
set have;
by Patient;
if first.Patient then n=0;
n+1;
run;
proc transpose data=temp out=temp2;
by Patient n;
var ALT AST INR ;
run;
proc transpose data=temp2 out=want(drop=_NAME_) delimiter=_;
by Patient ;
id _NAME_ n;
var col1;
run;
This worked great! Thank you so much, I really appreciate it.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.