## Lenght statement

Solved
Super Contributor
Posts: 1,041

# Lenght statement

Hi,

I have variable VAR like shown and is left justified:

length of VAR is \$5

Does that mean 593 and 555 has 2 extra spaces after the number!!!

and like wise 6940 has one space after the number???

VAR

593

6940

555

Thanks

Accepted Solutions
Solution
‎06-03-2014 03:27 PM
Super User
Posts: 6,785

## Re: Lenght statement

I can't comment about the PRXCHANGE function, but otherwise the right pieces are in place.  WANT will have a length of 5, and any values that are shorter than 5 characters will have blanks added to the end.

All Replies
Super Contributor
Posts: 578

## Re: Lenght statement

I would answer it this way:

They all have 5 bytes allocated to the variable.  The Length function returns the length of a non-blank character string, excluding trailing blanks, and returns 1 for a blank character string

Super Contributor
Posts: 1,041

## Re: Lenght statement

I was asking because of the following condition and wondering if length 5 could be used

Diagnosis codes with fewer than five digits should be padded with spaces (not zeros) on the right.

Thanks

Super Contributor
Posts: 578

## Re: Lenght statement

SAS wouldn't add zeroes unless you coded it to do that.  Default is spaces.

Super Contributor
Posts: 1,041

## Re: Lenght statement

hi,

So what I did is right???

I am not adding zeros ..

then is this below condition satisfied???

Diagnosis codes with fewer than five digits should be padded with spaces (not zeros) on the right.

Super User
Posts: 6,785

## Re: Lenght statement

Yes, extra blanks are stored at the end.  In a DATA step, that makes no difference and you could use any of these statements to get the same result:

if var='593' then do;

if var='593  ' then do;

if var='593          ' then do;

However, if you are using pass-through SQL with a WHERE clause, a database might not process trailing blanks in the same way.  The WHERE clause might have to add the TRIM function.

Super Contributor
Posts: 1,041

## Re: Lenght statement

/*CHECKING TO SEE IF THIS ONE SATIFIES THAT CONDITION*/

data have;

input x \$20.;

cards;

930.0

934

941.04

V12.09

V10.46

696.1

008.45

;

run;

data want;

set have;

length want \$5.;

want=prxchange('s/\.//',-1,x);

run;

Solution
‎06-03-2014 03:27 PM
Super User
Posts: 6,785

## Re: Lenght statement

I can't comment about the PRXCHANGE function, but otherwise the right pieces are in place.  WANT will have a length of 5, and any values that are shorter than 5 characters will have blanks added to the end.

Super Contributor
Posts: 1,041

## Re: Lenght statement

great.

I got help on this PRXCHANGE function .

this basically removes dots from the codes

V10.46 becomes V1046

930.0 becomes 9300

934 stays 934

Do you think there is any better way to do this???

Super User
Posts: 6,785

## Re: Lenght statement

Are you sure that is all that PRXCHANGE is doing?  I'm not familiar enough with it to comment, but it would have been simple to code:

want = compress(x, '.');

That would remove the dots and might be easier to understand.

Super User
Posts: 8,127

## Re: Lenght statement

If you want to remove particular characters from a string then use the COMPRESS() function.

want = compress(x,'.');

Posts: 3,167

## Re: Lenght statement

data have;

input x \$20.;

nondot=compress(x,'.');

cards;

930.0

934

941.04

V12.09

V10.46

696.1

008.45

;

run;

Posts: 1,270