BookmarkSubscribeRSS Feed
Mgarret
Obsidian | Level 7

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

  • Yahoo_AS_acq_fios_3x_NeonLastChanceNAT_8999_AmazonVisa_Flash_10282013_728x90.swf | AK & REVSCI

  • Google_AS_acq_fios_3x_NeonLastChancePOTOMAC_8999_AmazonVisa_Flash_10282013_728x90.swf | AK & REVSCI

  • acq_fios_3X_MadDashPot_7999_Visa_Flash_11172013_728x90.swf (copy)

  • AOL_AS_acq_fios_3X_SpeedTiersNY_8999_NAC_Flash_1012013_728x90.swf

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. 

2 REPLIES 2
data_null__
Jade | Level 19

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.

ballardw
Super User

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.

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
  • 2 replies
  • 905 views
  • 0 likes
  • 3 in conversation