Hi,
I think we can solve it by using Transpose, but it's kind of tricky. Now I have data like,
ID | Unit | Class | Term | Class_factor | Term_Factor | Tol |
01 | 1 | Standard | 6mon | 1 | 1 | 1 |
01 | 2 | Supreme | 6mon | 1.5 | 1 | 1.5 |
02 | 1 | Standard | 12mon | 1 | 2 | 2 |
The following is what I want,
Variable | Value_01-1 | factor_01-1 | Value_01-2 | factor_01-2 | Value_02-1 | factor_02-1 |
Class | Standard | 1 | Supreme | 1.5 | Standard | 1 |
Term | 6mon | 1 | 6mon | 1 | 12mon | 2 |
Tol | 1 | 1.5 | 2 |
Many thanks!
I can now split it. But it get some difficulties to combine them.
data original;
length key $25;
set original;
key = compress(ID||'-'||put(Unit,z2.),,'kadp');
run;
proc transpose data=original out=testc(rename=(_NAME_ = Variable)) preffix = Value_;
id key;
var _CHAR_;
run;
proc transpose data=original out=testn(rename=(_NAME_ = Variable)) preffix = Factor_;
id key;
var _NUMERIC_;
run;
Hi,
I think we can solve it by using Transpose, but it's kind of tricky. Now I have data like,
ID | Unit | Class | Term | Class_factor | Term_Factor | Tol |
01 | 1 | Standard | 6mon | 1 | 1 | 1 |
01 | 2 | Supreme | 6mon | 1.5 | 1 | 1.5 |
02 | 1 | Standard | 12mon | 1 | 2 | 2 |
The following is what I want,
Variable | Value_01-1 | factor_01-1 | Value_01-2 | factor_01-2 | Value_02-1 | factor_02-1 |
Class | Standard | 1 | Supreme | 1.5 | Standard | 1 |
Term | 6mon | 1 | 6mon | 1 | 12mon | 2 |
Tol | 1 | 1.5 | 2 |
Many thanks!
I can now split it. But it get some difficulties to combine them.
data original;
length key $25;
set original;
key = compress(ID||'-'||put(Unit,z2.),,'kadp');
run;
proc transpose data=original out=testc(rename=(_NAME_ = Variable)) preffix = Value_;
id key;
var _CHAR_;
run;
proc transpose data=original out=testn(rename=(_NAME_ = Variable)) preffix = Factor_;
id key;
var _NUMERIC_;
run;
please try
proc transpose data=original out=testc(where=(variable ne 'key') rename=(_NAME_ = Variable)) prefix = Value_;
id key;
var _CHAR_;
run;
proc transpose data=original out=testn(rename=(_NAME_ = Variable)) prefix = Factor_;
id key;
var _NUMERIC_;
run;
data want;
merge testc testn;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.