CAT length explosion

Accepted Solution Solved
Reply
Contributor
Posts: 49
Accepted Solution

CAT length explosion

Howdy,

I'm construction a string out of a bunch of integers of specified lengths.

I was using CATT (since it looks like it auto-trims = super cool) however I'm still running into an end length on my string of a default 200 characters, when it should be 24. The below is my calc showing variable transformation to string with length. Upon concatenation the end product is 200 long... and lame.

CATT((PUT(t1.fiscal_year_idnt,z4.0)),(PUT(t1.fiscal_month_idnt,z2.)),(PUT(t1.fiscal_week_idnt,z2.)),(PUT(t1.fiscal_day_idnt,z2.)),(PUT(t1.loc_idnt,z4.)),(PUT(t1.register_num,z2.)),t1.txn_num,(PUT(t1.tran_type_idnt,z2.)))

TS


Accepted Solutions
Solution
‎02-24-2015 11:35 AM
Super User
Posts: 19,770

Re: CAT length explosion

Posted in reply to GalacticAbacus

Formats (i.e. $24, Z24)  do not affect the length of a variable.

I don't know if there's a way to specify the length of a variable in Query builder, perhaps post this in the SAS EG forum so someone more familiar with EG can answer.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,137

Re: CAT length explosion

Posted in reply to GalacticAbacus

By default when we use the character functions, the variable length is assigned 200bytes. i believe if you wish tochange the length then give a separate length statement and assign the desired length the variable.

Thanks,
Jag
Contributor
Posts: 49

Re: CAT length explosion

Posted in reply to Jagadishkatam

Sorry I should have specified, I've tried limiting the length of the Cat variable by multiple methods. I've specified $24., I've tried trimming it then assigning the format, I've run the variable as 200 then tried to shrink it down. It's unstoppable....

Respected Advisor
Posts: 3,799

Re: CAT length explosion

Posted in reply to GalacticAbacus

Show your work and RTM.

SAS Super FREQ
Posts: 708

Re: CAT length explosion

Posted in reply to GalacticAbacus

The code looks like it is a column expression in Proc SQL.

A column expression can look like:

CATT( ... ) as colName length=24

So you can specify the length of the variable, see also sample below:

proc sql;
 
create table sample as
 
select
    catt(name, sex, age)
as myColumn length=32
 
from
    sashelp.class
  ;
quit;

proc contents data=sample;
run;

Bruno

Contributor
Posts: 49

Re: CAT length explosion

Posted in reply to Bruno_SAS

Sorry, I'll provide additional detail. I'm working withing the SAS EG query construct wizard. While yes I could take this into a program node within the interface and switch to sequel expression, this query is using the "query builder". I have tried the following.

Variable x = CATT((PUT(t1.fiscal_year_idnt,z4.0)),(PUT(t1.fiscal_month_idnt,z2.)),(PUT(t1.fiscal_week_idnt,z2.)),(PUT(t1.fiscal_day_idnt,z2.)),(PUT(t1.loc_idnt,z4.)),(PUT(t1.register_num,z2.)),t1.txn_num,(PUT(t1.tran_type_idnt,z2.)))

Output: length 200

I have tried the same as above, but specifying a format statement within the query builder output "$24." Output length: 200

I have tried running the above then just limiting the length afterward to z24. Output length: 200

Variable x = CATT((PUT(t1.fiscal_year_idnt,z4.0)),(PUT(t1.fiscal_month_idnt,z2.)),(PUT(t1.fiscal_week_idnt,z2.)),(PUT(t1.fiscal_day_idnt,z2.)),(PUT(t1.loc_idnt,z4.)),(PUT(t1.register_num,z2.)),t1.txn_num,(PUT(t1.tran_type_idnt,z2.)))

Variable x = SUBSTR(Variablex,1,24) with a format statement within the query builder specifying $24. Output length: 200


Variable x = TRIM(CATT((PUT(t1.fiscal_year_idnt,z4.0)),(PUT(t1.fiscal_month_idnt,z2.)),(PUT(t1.fiscal_week_idnt,z2.)),(PUT(t1.fiscal_day_idnt,z2.)),(PUT(t1.loc_idnt,z4.)),(PUT(t1.register_num,z2.)),t1.txn_num,(PUT(t1.tran_type_idnt,z2.))),z24.

Output: length 200


So there is something missing.... I thought maybe i was specifying a length which was too small for the greatest value of my output so I specified a length of 40 and it still defaulted to 200.


TS

Solution
‎02-24-2015 11:35 AM
Super User
Posts: 19,770

Re: CAT length explosion

Posted in reply to GalacticAbacus

Formats (i.e. $24, Z24)  do not affect the length of a variable.

I don't know if there's a way to specify the length of a variable in Query builder, perhaps post this in the SAS EG forum so someone more familiar with EG can answer.

Contributor
Posts: 49

Re: CAT length explosion

I ended up having to take it out of the query builder and just applying length statements. I was probably just confusing length with format statements. Thx.

SAS Super FREQ
Posts: 708

Re: CAT length explosion

Posted in reply to GalacticAbacus

Maybe for a next time, when creating a new column in the query builder of SAS Enterprise Guide, one can specify a length, see screenshot below:

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 464 views
  • 4 likes
  • 5 in conversation