Shouldn't the compress function eliminate the repeating "20"?
27 data check;
28 set in.CK14_data2(firstobs=2 obs=2);
29 put state state hex16.;
30 statex=compress(state,'20'x);
31 put statex statex hex16.;
32 run;
DC 4443202020202020
DC 4443202020202020
It did. Remember that SAS only has two types of variables. Floating point numbers and fixed length character strings.
When you assigned the value 'DC' to the variable the result is that the rest of the variable is filled with spaces.
76 data test; 77 length state1 $2 state2 $8 ; 78 state1='DC'; 79 state2='DC'; 80 put (state1 state2) (=$hex./); 81 run; state1=4443 state2=4443202020202020
I think in this case the Put is showing the trailing spaces to the length of the defined variable.
Example:
265 data _null_; 266 length y $ 6; 267 y='D'; 268 put y= hex16. ; 269 run; y=442020202020
No actual spaces assigned after the D but the result with 5 pairs of 20 in the hex output is shown.
This is somewhat analogous to using a 10.8 format to display the value of 1. The format includes the 8 zeroes after the decimal.
Hexadecimal 20 is the ASCII space character. Character variables in SAS are always padded with spaces beyond the last non-blank character to the length of the variable. That is why compressing space characters will have no effect to the right of the last non-blank character.
statex=compress(state,'20'x);
This means: Remove all \x20 characters -aka spaces- from the value stored in the variable STATE.
It's the same as:
statex=compress(state);
and the function does that. Then the value is stored in the variable.
If the variable is longer than the value, the value is right-padded with spaces.
If the variable is shorter than the value, the value is truncated.
It did. Remember that SAS only has two types of variables. Floating point numbers and fixed length character strings.
When you assigned the value 'DC' to the variable the result is that the rest of the variable is filled with spaces.
76 data test; 77 length state1 $2 state2 $8 ; 78 state1='DC'; 79 state2='DC'; 80 put (state1 state2) (=$hex./); 81 run; state1=4443 state2=4443202020202020
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: