10-13-2013 02:38 AM
I have a variable zipcode in my file. I want to do two things. First, there are some observations that start with States, for example, CA 92126. I want to get rid of CA to show only 92126. Second, there are some zip codes that include four digits sub zip, for example, 33180-3123. I want to get rid of the last four digits, only keep 33180. Please help. Thanks.perl
10-13-2013 05:30 PM
Kind of .. sort of. Yes they are removed by the second argument but SAS will right pad with spaces anyhow to fill the length of the field. If you really don't want any spaces, and all of your entries will have 5 characters, I would simply use the code to create a new variable with a length of $5.
informat zip $12.;
input zip &;
data want (drop=_;
length zip $5;
set have (rename=(zip=_zip));
10-13-2013 05:40 PM
Thanks. Then there will be a question if I want to merge by some name variables. For example, I have a name James Bond in set 1, and James Bond in set 2. I want to merge them together. But name variable in set 1 is $20. and name variable in set 2 is $30. Will SAS treat this name observation James Bond as match?
10-13-2013 05:55 PM
Typically, probably. However, if the file with the shorter lengths is specified first in the merge, you will get a warning:
WARNING: Multiple lengths were specified for the BY variable name by input data sets. This may
cause unexpected results.
Need further help from the community? Please ask a new question.