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
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.
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
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
SAS wouldn't add zeroes unless you coded it to do that. Default is spaces.
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.
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.
/*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;
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.
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???
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.
If you want to remove particular characters from a string then use the COMPRESS() function.
want = compress(x,'.');
data have;
input x $20.;
nondot=compress(x,'.');
cards;
930.0
934
941.04
V12.09
V10.46
696.1
008.45
;
run;
In $w. informats w represents the total number of columns that contain the raw data filed.
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 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.