Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use & as a Character and not a Macro Variable

Status
Not open for further replies.

imiddlebrookuk

Technical User
Sep 25, 2008
1
GB
Im having a problem with the ampersand quoted after then in the statement below because i've used double quotes SAS thinks that the ampersand is the start of a macro, now the usual way to get round it would be to use single quotes but i can't do this because Italy has an apostrophe and SAS think its end of quote. is there a way of getting round this?

Case
When TotalTours.Brand = "J" and TotalTours.Description = 'Innsbruck & Lake Garda' then "Innsbruck & Italy's Lake Garda" end

 
I tried your line of text in the data step using SAS 8.2 and 9.1.3 and it worked correctly. Meaning SAS read the string and used it as a string and not a macro oper.
Could there be a problem with your code? In the worst case scenerio what you need to do is 'mask' the '&'. You can use the '%' in the %str() macro function for this purpose.

Does your code look like this?
Code:
select;

When (TotalTours.Brand = "J" and
      TotalTours.Description = 'Innsbruck & Lake Garda') 
      "Innsbruck & Italy's Lake Garda" 
end;
If it does I think you're missing part of your assignment statement.

Klaz

 
If you are trying to write this code is base sas9 then the ampersands are the least of your worries. Base SAS doesn't support object orientation, hence no methods and dot notation - the exception being the new hash objects. Is this perhaps SAS Component Language?

For the masking the ampersand, use % in front of the special characters in a %str() as Klaz mentioned. I generally find putting the whole string in a %nrstr function (stops the resolution of ampersands) more straightforward.

Code:
%nrstr(Innsbruck & Italy's Lake Garda)
 
Ok my bad, realized this is SQL (I need coffee), forget my mumbo jumbo above - apart from the macro quoting paragraph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top