BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Lost_Gary
Quartz | Level 8

Is there a way to control the variable lengths within the Proc Transpose?  I have some lengthy output that appears to be truncated when transposed.  

 

This code is an example:

data aarfm ;

set sashelp.aarfm (obs=10);

run;

proc  transpose data=aarfm out=test;

id key;

run;

proc print data=test;

run;

In the output there is observation #9 that reads:

FREQUENCY_GROUP_INT_NOT_BETWEEN_

it just cuts off.  is there anyway to make it longer?  

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Lost_Gary wrote:

Is there a way to control the variable lengths within the Proc Transpose?  I have some lengthy output that appears to be truncated when transposed.  

 

This code is an example:

data aarfm ;

set sashelp.aarfm (obs=10);

run;

proc  transpose data=aarfm out=test;

id key;

run;

proc print data=test;

run;

In the output there is observation #9 that reads:

FREQUENCY_GROUP_INT_NOT_BETWEEN_

it just cuts off.  is there anyway to make it longer?  

 

Thanks!


Not very clear on your description as to where that value is getting cut off. However since that string you show has the magic length of 32, which is the longest that any SAS variable can be, I am going to say that you have ID values greater than 32 characters in length (I see an assigned format of $60 so that looks very plausible) and the result will not support that. When I look at that data set there are lengths between 10 and 40 characters. So without changing the values of Key you will get truncated for the 12 key values of 33 or greater characters.

 

I am a bit dubious about your entire transpose. Normally I would suggest using that variable as an IDLABEL, since labels may be longer than 32 characters. But depending on your input data you can very well have different variables with the same label or different values of the transposed variables getting assigned to a wrongly labeled variable. I am assuming that you are using the AARFM as an example, and thank you for providing one, but if you have any BY groups with different values of ID values you may need another approach.

View solution in original post

7 REPLIES 7
vellad
Obsidian | Level 7
Hey Gary can you check the code you posted here again? I don't see how you could get 9 observations AFTER you transpose a dataset with 10 records, using the id statement alone.
ballardw
Super User

@vellad wrote:
Hey Gary can you check the code you posted here again? I don't see how you could get 9 observations AFTER you transpose a dataset with 10 records, using the id statement alone.

Since the stated base data set has exactly one numeric variable, lineno, with one value =1, and proc transpose will attempt to transpose all numeric variables when no VAR statement is present I doubt that his out has 2 observations. Unless @Lost_Gary transpose the data second time.

vellad
Obsidian | Level 7
Yes he must have transposed it a second time, or something else is going on. Perhaps he meant 'variable 9' instead of 'observation 9'?
Reeza
Super User
I suspect s/he intended to refer to variable 9.
ballardw
Super User

@Lost_Gary wrote:

Is there a way to control the variable lengths within the Proc Transpose?  I have some lengthy output that appears to be truncated when transposed.  

 

This code is an example:

data aarfm ;

set sashelp.aarfm (obs=10);

run;

proc  transpose data=aarfm out=test;

id key;

run;

proc print data=test;

run;

In the output there is observation #9 that reads:

FREQUENCY_GROUP_INT_NOT_BETWEEN_

it just cuts off.  is there anyway to make it longer?  

 

Thanks!


Not very clear on your description as to where that value is getting cut off. However since that string you show has the magic length of 32, which is the longest that any SAS variable can be, I am going to say that you have ID values greater than 32 characters in length (I see an assigned format of $60 so that looks very plausible) and the result will not support that. When I look at that data set there are lengths between 10 and 40 characters. So without changing the values of Key you will get truncated for the 12 key values of 33 or greater characters.

 

I am a bit dubious about your entire transpose. Normally I would suggest using that variable as an IDLABEL, since labels may be longer than 32 characters. But depending on your input data you can very well have different variables with the same label or different values of the transposed variables getting assigned to a wrongly labeled variable. I am assuming that you are using the AARFM as an example, and thank you for providing one, but if you have any BY groups with different values of ID values you may need another approach.

Tom
Super User Tom
Super User

Don't try to use a variable with a length of $60 as the ID variable used to define the NAMES of the variables in the new dataset.

Use some other variable that has values of an appropriate length.  You can use KEY as the variable in the IDLABEL option instead.

data aarfm ;
  row +1;
  set sashelp.aarfm (obs=10);
run;

proc  transpose data=aarfm out=test;
  id row;
  idlabel key;
run;

proc print label data=test;
run;
Reeza
Super User

In this particular case it isn't a format issue, it's the name of the variable. SAS variables can only be 32 characters so there are workarounds in this case but not a fix per se. 

 

Depending on what you're trying to do there may be other options. For example, if you were trying to display a report you could use PROC REPORT with across which would not have the same limitation or you could shorten the variable name while adding the usage of the IDLABEL statement so that the appearance was correct, regardless of the name. I had to expand my example to 11 to find the record you noted so not sure if we have different aarfm data sets or something else is going on. 

 

data aarfm;
	set sashelp.aarfm (obs=12);
run;

proc transpose data=aarfm out=test;
	id key;
	idlabel key;
run;

proc print data=test label;
run;

@Lost_Gary wrote:

Is there a way to control the variable lengths within the Proc Transpose?  I have some lengthy output that appears to be truncated when transposed.  

 

This code is an example:

data aarfm ;

set sashelp.aarfm (obs=10);

run;

proc  transpose data=aarfm out=test;

id key;

run;

proc print data=test;

run;

In the output there is observation #9 that reads:

FREQUENCY_GROUP_INT_NOT_BETWEEN_

it just cuts off.  is there anyway to make it longer?  

 

Thanks!


 

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
  • 7 replies
  • 5701 views
  • 7 likes
  • 5 in conversation