BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
spirto
Obsidian | Level 7

hi everyone,

im trying to use a macro variable in a name literal to reference an excel sheet but it is not working for me. i can get the libname statement to work but not the data step. is there anyway to evaluate a macro variable inside the name literal? here is my code and error:

%let prot=132;

libname stabdata "C:\Desktop\p&prot..xlsx";

data p&prot.data; set stabdata.'p&prot.data$'n; run;

libname stabdata clear;

i would like the data step to evaluate as data p132data; set stabdata.'p132data$'n; run; but i get the following error

data p&prot.data; set stabdata.'p&prot.data$'n; run;

ERROR: File STABDATA.'p&prot.data$'n.DATA does not exist.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Macro variables do not expand within single quotes. Convert to using double quotes.

stabdata."p&prot.data$"n;

View solution in original post

4 REPLIES 4
Haikuo
Onyx | Level 15

In your SAS explorer or open the excel sheet, get the sheet name you need. I suspect that you don't have a sheet name called p123data.

Haikuo

spirto
Obsidian | Level 7

Haikuo-

i checked SAS explorer and the excel sheet is listed. I believe the problem is that the macro variable is not being resolved.

if i manually change the stabdata.'p&prot.data$'n to stabdata.'p132data$'n then everything works ok

Tom
Super User Tom
Super User

Macro variables do not expand within single quotes. Convert to using double quotes.

stabdata."p&prot.data$"n;

spirto
Obsidian | Level 7

Excellent!! I didn't know that SAS literals worked with double quotes...I was always under the impression that name, time, date, etc literals needed single quotes.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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