any alternative of CATT function

Reply
New Contributor
Posts: 3

any alternative of CATT function

" CATT(REPEAT('0',6-length(EE_LOCATION)),EE_LOCATION);  " i have used CATT function to set length of EE_LOCATION to 6.now the problem is that i want to do same work bt dont want to use CATT and REPEAT.any alternative.?

Super User
Posts: 17,784

Re: any alternative of CATT function

IF ee_location is a number you can use z. format.

If character use translate function with 0's replacing spaces, once you've set the length:

data padded_data_dsn; length key $5;
  drop raw_data;
  set raw_data_dsn(rename=(key=raw_data));
  key = translate(right(raw_data),'0',' ');
run;

New Contributor
Posts: 3

Re: any alternative of CATT function


ee_location is VARCHAR.

Super Contributor
Posts: 297

Re: any alternative of CATT function

DATA WANT;

EE_LOCATION = "1111";

WANT = CATT(REPEAT('0',6-length(EE_LOCATION)),EE_LOCATION);

WANT1 = PUT(INPUT(EE_LOCATION,4.),Z7.);

RUN;

Is this what you want?

New Contributor
Posts: 3

Re: any alternative of CATT function

i have  used TRANSLATE now.i want length of EE_LOCATION '6'.but wid with leading zeros..but TRANSLATE and RIGHT function giving me ans with zeros in the end.


Super Contributor
Posts: 339

Re: any alternative of CATT function

data want;

ee_location="1111"; /* assuming that EE_LOCATION format might be different from $6. if not, you can remove the put() function below and just use ee_location*/

want=(translate(right(put(ee_location, $6.)), '0', ' ');

run;

Not entirely sure that's what you are asking for but anyway. For so long as Right is applied before translate, it should fix your issue of right zero-padding.

Vincent

Super User
Posts: 17,784

Re: any alternative of CATT function

It works for me, so either there's a mistake in your code or your data has something else in it. Post your code and an example of your data if it doesn't work for you.

data test;

    length var $6.;

    var="ABCD";

    output;

    var=translate(right(var), "0", " ");

    output;

run;

proc print data=test;run;

Respected Advisor
Posts: 3,124

Re: any alternative of CATT function

Another alternative is to use substr() on the left:

data _null_;

newvar='000000';

var='abcd';

substr(newvar,7-lengthn(compress(var)))=compress(var);

put var= newvar=;

run;

Haikuo

Ask a Question
Discussion stats
  • 7 replies
  • 241 views
  • 1 like
  • 5 in conversation