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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.