DATA Step, Macro, Functions and more

Mask balanced quotes.

Reply
Super Contributor
Posts: 647

Mask balanced quotes.

%let a='medmark novoseven 080109103600$';
%put &a;

How to mask the quotes (which are balanced) and just output
medmark novoseven 080109103600$
SAS Super FREQ
Posts: 8,743

Re: Mask balanced quotes.

Hi:
It is generally a bad idea to "prequote" macro variables. The quotes belong to the SAS statement where the macro variable is used. For example:
[pre]
%let amt = 5000;

title "Criteria: Amount GT &amt";
versus
where amount gt &amt;
[/pre]

In the first instance, the quotes belong to the title statement. In the WHERE statement, if you had prequoted the value for &AMT, you probably would have generated an incorrect WHERE statement, because there's a difference between:
[pre]
where amount gt 5000;
versus
where amount gt '5000';
[/pre]

But let's say that your WHERE statement -did- need quotes...this is what you want to generate:
[pre]
where name = "Alfred";
[/pre]

and your macro variable is named WANT...

You should create &WANT like this:
[pre]
%let want = Alfred;
where name = "&want";
[/pre]

Or, here's another example of where you might need quotes for syntax purposes:
[pre]
%let muppet = Kermit the Frog;

data sesame;
length character $20;
character = "&muppet";
run;
[/pre]

While it might be tempting to prequote the value Kermit the Frog, the quotes actually belong to the assignment statement where the &MUPPET macro variable is being used and the usage context and quoting requirements are known.

Why did you have quotes when you assigned a value to &A??? How are you using that macro variable?

These previous forums postings may help clarify the issue of quotes and macro variables:
http://support.sas.com/forums/thread.jspa?messageID=16560䂰
http://support.sas.com/forums/thread.jspa?messageID=23099娻
http://support.sas.com/forums/thread.jspa?messageID=16160㼠


cynthia
Super Contributor
Posts: 647

Re: Mask balanced quotes.

Cynthia,
Thanks for the info.
The reason for masking the quotes is:
I'm trying to pass the worksheet name in the select select statement.

******I get all the wksheet names into tabnaes table.*******
proc sql;
connect to excel (path="&inpt.\Walgreens 2009 08.xls");
create table tabnaes as
select table_name from connection to excel (jet::tables);
quit;



proc sql;
delete from tabnaes where table_name like '%(2)%' or table_name like '%NAMES%';
select table_name into:wksht from tabnaes;
quit;

%put &wksht resolves to 'medmark novoseven 080109103600$'


When pass the wksht name, it should be without quotes as per syntax.
So I thought I can create a macro variable and then pass it without quotes as shown below.

If I dont create a macro variable, i will have to manually change the worksheet name everytime.(as shown in second select statement below)

proc sql;
connect to excel (path="&inpt.\Walgreens 2009 08.xls"
header=no mixed=yes );

create table walgreens as
select * from connection to excel
(select * from [medmark novoseven 080109103600$]);
disconnect from excel;
quit;
Frequent Contributor
Posts: 102

Re: Mask balanced quotes.

SASPhile,

To re-iterate what Cynthia is saying, why did you put the quotes on it in the first place? Macro variable assignments do not need quotes, so unless you want them to show up when you resolve the macro variable, just don't include them . Like this:
---------------------------------------
%let a=medmark novoseven 080109103600$;
%put &a;
Respected Advisor
Posts: 3,777

Re: Mask balanced quotes.

Reading the rest of the tread I don't know if I understand what you are doing. But you can easily DEQUOTE the string with the function of the same name...

[pre]
9672 %let a='medmark novoseven 080109103600$';
9673 %let dequoteA = %sysfunc(dequote(%superQ(A)));
9674 %put &a (&dequoteA);
'medmark novoseven 080109103600$' (medmark novoseven 080109103600$)
[/pre]

You may not need %QSUPERQ but I probably wont hurt.
Super Contributor
Posts: 647

Re: Mask balanced quotes.

Thanks for the help Data _null_.
Ask a Question
Discussion stats
  • 5 replies
  • 165 views
  • 0 likes
  • 4 in conversation