Help using Base SAS procedures

32 byte restriction in PROC TRANSPOSE

Reply
Occasional Contributor
Posts: 5

32 byte restriction in PROC TRANSPOSE

I'm trying to automate a process.

My incoming dataset has a single row per customer and has many X-variables tied to a Yes or No if the customer has purchased the product.

I need to Transpose the data but I run into the 32 character limitation in PROC TRANSPOSE.    I've forced the variables to be less than 32characters but wonder if there's a way to circumvent this challenge and keep the original long variable names. 

CustomerNum    Product1  Product2   ProductHasaVariableNamethatiswelloverthe32byterestrictioninTranspose

1234567                 Yes              No                                          Yes

Respected Advisor
Posts: 3,777

Re: 32 byte restriction in PROC TRANSPOSE

SAS Names are limited to 32 bytes.

However you can use the IDLABEL statement in PROC TRANSPOSE to create a variable LABEL from a string that is much longer. 

If you can't figure it post some sample data.  Including an example of what you have is always helpful.

PROC Star
Posts: 7,356

Re: 32 byte restriction in PROC TRANSPOSE

Please explain. SAS variable names can't be more than 32 characters long. It's not just a proc transpose restriction.

Super User
Super User
Posts: 6,495

Re: 32 byte restriction in PROC TRANSPOSE

First do you even need to transpose the data at all?  What are you doing with it?  Perhaps you can analyze it in a the original tall-skinny format.

Second the variable NAME cannot be longer than 32, but you could use the product name as the LABEL instead.

data have ;

  length CustomerNum $20 Product $200 Status $3 ;

  input CustomerNum Product Status ;

cards;

1234567 Product1 Yes

1234567 Product2 No

1234567 ProductHasaVariableNamethatiswelloverthe32byterestrictioninTranspose Yes

ABCDEF  Product2 Yes

;;;;

proc sort ;

  by product ;

run;

data have2 ;

  do until (last.product);

    set have ;

    by product ;

    _name_='VAR'||put(_n_,Z4.) ;

    output;

  end;

run;

proc sort ;

  by customernum _name_ ;

run;

proc transpose data=have2 out=want (drop=_name_) ;

  by customernum ;

  id _name_;

  idlabel product ;

  var status ;

run;

proc print;

run;

proc print label ;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 240 views
  • 0 likes
  • 4 in conversation