Hi-
I have a variable called CreativeName with many different string values. Some of the values (not all) have parts of the strings which need to be deleted. If I use COMPRESS the characters are deleted anywhere in the string; and not the part of the string I specify. The parts that need to be deleted can be found at the beginning or the end of the string value.
Here are some examples of the strings that need to be cleaned/modified
This is what I have:
Data want;
Set have;
CreativeName= compress(CreativeName,’(Copy)’);
CreativeName= compress(CreativeName,’AOD_AS_’);
CreativeName= compress(CreativeName,’AOL_AS_’);
CreativeName= compress(CreativeName,’Google_AS_’);
CreativeName= compress(CreativeName,’Google_’);
CreativeName= compress(CreativeName,’Yahoo_AS_’);
CreativeName= compress(CreativeName, '| AK & REVSCI');
CreativeName= compress(CreativeName, '| AK'); run;
Also for values that are ‘FiOS Presents’ I have to add ‘MF’ to the end. Can I use the TRANSWORD function? Any assistance is appreciated.
Compress you keep using that function, I don't think it means what you think it means.
Compress does not operate at the word level.
Perhaps TRANSTRN or a regular expression would be better than compress.
Either TRANWRD or TRANSTR work if you want to replace 'FiOS Presents' with 'FiOS Presents MF'. You want to make sure that the resulting length doesn't exceed the current length of the variable.
When I have a problem like this I generally create a new variable that starts with the original value of the problem variable and manipulate that as invariably I create a rule, usually involving a short string such as your |AK, that creates a problem when it replaces unforethought occurences.
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 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.