BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

Hi,

I use the below code to concat few date into text.

It works fine but the column itself is much bigger than it suppose to be even though I put the Length statement.

The output is:

T:11:59 /11:59 /11:59                         . With a lot of blank after

When I check column attributes, it shows: Length 25, Format$25., Informat $25.

 

The original clock_time attribute is: Length 8, TIME10., TIME20.3.

 

Can you please help to make the column width is 25?

Thanks,

HHC

 

data export; 
length time $ 25;
set a; 
time = catt("T: ", put(clock_time,time5.),"  /  " , put(clock_time,time5.),"  /  " , put(clock_time,time5.) );
RUN;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The CATT() function with TRIM() the value (remove the TRAILING spaces before concatenating them.

That is why the spaces after the colon and slashes are removed.

 

Are you just confused because SAS stores strings a FIXED length?

If you define TIME as 25 bytes long and the store strings that are only 2+5+3+5+3+5 = 23 characters long then there will be two extra spaces added to pad the length to the full 25 bytes.

If you switch to CAT() instead of CATT() then the spaces will be include so you will make a string that is 3+5+5+5+5+5=28 bytes long so the last 3 characters of the last copy of the TIME will be lost when you store the 28 bytes into a variable that can only hold 25 bytes.

View solution in original post

5 REPLIES 5
ballardw
Super User

It would help if you showed exactly what you expect for the result. "Length 25" is sort of indeterminate.

 

If you are using things like this in the CATT function to add spaces then  you don't want the CATT function. The second T sort of means remove the trailing spaces.

"  /  " 

 Try using the CAT function instead of CATT.

hhchenfx
Barite | Level 11

 2023-01-25_23-47-52.jpg

 

So the SAS file has time column look like above with the width quite big. And when I export to excel, the column is wide as well. 

I am not sure why.

HHC

ballardw
Super User

@hhchenfx wrote:

 2023-01-25_23-47-52.jpg

 

So the SAS file has time column look like above with the width quite big. And when I export to excel, the column is wide as well. 

I am not sure why.

HHC


I gave up trying to figure out how Excel will display any given values a long time ago. Random wrapping of values, picking a display width narrow or longer than declared lengths of values, changing actual values (when opening CSV or tab delimited files).

Again I say, show what you expect for output.

SASKiwi
PROC Star

You've already defined TIME with a LENGTH of 25 characters and checked that the attributes are correct. Your string "T:11:59 /11:59 /11:59" is 21 characters long so it will be stored in TIME with 4 blank spaces on the end. Why do you think "column width" is not 25? 

Tom
Super User Tom
Super User

The CATT() function with TRIM() the value (remove the TRAILING spaces before concatenating them.

That is why the spaces after the colon and slashes are removed.

 

Are you just confused because SAS stores strings a FIXED length?

If you define TIME as 25 bytes long and the store strings that are only 2+5+3+5+3+5 = 23 characters long then there will be two extra spaces added to pad the length to the full 25 bytes.

If you switch to CAT() instead of CATT() then the spaces will be include so you will make a string that is 3+5+5+5+5+5=28 bytes long so the last 3 characters of the last copy of the TIME will be lost when you store the 28 bytes into a variable that can only hold 25 bytes.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 5 replies
  • 1029 views
  • 2 likes
  • 4 in conversation