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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 477 views
  • 0 likes
  • 2 in conversation