BookmarkSubscribeRSS Feed
jordenlam
Calcite | Level 5

Hi,

 

I think we can solve it by using Transpose, but it's kind of tricky. Now I have data like,

IDUnitClassTermClass_factorTerm_FactorTol
011Standard6mon111
012Supreme 6mon1.511.5
021Standard12mon122

 

The following is what I want,

VariableValue_01-1factor_01-1Value_01-2factor_01-2Value_02-1factor_02-1
ClassStandard1Supreme 1.5Standard1
Term6mon16mon112mon2
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;
3 REPLIES 3
jordenlam
Calcite | Level 5

Hi,

 

I think we can solve it by using Transpose, but it's kind of tricky. Now I have data like,

IDUnitClassTermClass_factorTerm_FactorTol
011Standard6mon111
012Supreme 6mon1.511.5
021Standard12mon122

 

The following is what I want,

VariableValue_01-1factor_01-1Value_01-2factor_01-2Value_02-1factor_02-1
ClassStandard1Supreme 1.5Standard1
Term6mon16mon112mon2
Tol 1 1.5 2

 

Many thanks!

jordenlam
Calcite | Level 5

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;
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 502 views
  • 0 likes
  • 2 in conversation