BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

12 REPLIES 12
DBailey
Lapis Lazuli | Level 10

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

robertrao
Quartz | Level 8

thanks for the reply.

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

DBailey
Lapis Lazuli | Level 10

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

robertrao
Quartz | Level 8

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.

Astounding
PROC Star

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.

robertrao
Quartz | Level 8

/*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;

Astounding
PROC Star

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.

robertrao
Quartz | Level 8

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???

Astounding
PROC Star

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.

Tom
Super User Tom
Super User

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

want = compress(x,'.');

Haikuo
Onyx | Level 15

data have;

input x $20.;

nondot=compress(x,'.');

cards;

930.0

934

941.04

V12.09

V10.46

696.1

008.45

;

run;

stat_sas
Ammonite | Level 13

In $w. informats w represents the total number of columns that contain the raw data filed.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 12 replies
  • 1231 views
  • 9 likes
  • 6 in conversation