BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
%let a='medmark novoseven 080109103600$';
%put &a;

How to mask the quotes (which are balanced) and just output
medmark novoseven 080109103600$
5 REPLIES 5
Cynthia_sas
SAS Super FREQ
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
SASPhile
Quartz | Level 8
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;
CurtisMack
Fluorite | Level 6
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;
data_null__
Jade | Level 19
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.
SASPhile
Quartz | Level 8
Thanks for the help Data _null_.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 819 views
  • 0 likes
  • 4 in conversation