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

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:

PatientALTASTINR
120241.01
133481.03
215301.11
217321.25
218331.30

 

 

Dataset I want to have:

Patientalt_1ast_1inr_1alt_2ast_2inr_2alt_3ast_3inr_3
120241.0133481.03...
215301.1117321.2518331.30

 

Thanks again!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
dgaribal
Fluorite | Level 6

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.

Ksharp
Super User
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;
dgaribal
Fluorite | Level 6

This worked great! Thank you so much, I really appreciate it.

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