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;
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.
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.
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
@hhchenfx wrote:
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.
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?
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.
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!
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.