BookmarkSubscribeRSS Feed
Rickaroo
Calcite | Level 5

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

3 REPLIES 3
data_null__
Jade | Level 19

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.

art297
Opal | Level 21

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

Tom
Super User Tom
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1327 views
  • 0 likes
  • 4 in conversation