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

Hello!

We have 9.2 and 9.4 in shop.

However the following code (with different datafile and dbms characteristics) works in 9.4 but not in 9.2.

We have to make it to run on machine with 9.2

%macro readexcel(sheet);

proc import out= &sheet

datafile = "&path\&name..xls"

dbms = EXCEL2000 REPLACE;

sheet ="&sheet";

getnames=yes;

run;

data &sheet;

length nm $40;

set &sheet;

nm=symget('sheet');

run;

%mend readexcel;

 

When macro is executed all data from the sheet is there in the set, but column "nm"  that suppose to have Sheet name is empty, and we get message:

NOTE: Invalid argument to function SYMGET at line 2 column 47.

Thanks. 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Why are you using symget and not the macro variable directly? 

 

Nm="&sheet";

 

Looks like symget expects double quotes. From the docs

 

argument
can be one of the following items:

the name of a macro variable within double quotation marks but without an ampersand
the name of a DATA step character variable, specified with no quotation marks, which contains a macro variable name
a character expression that constructs a macro variable name

View solution in original post

2 REPLIES 2
Reeza
Super User

Why are you using symget and not the macro variable directly? 

 

Nm="&sheet";

 

Looks like symget expects double quotes. From the docs

 

argument
can be one of the following items:

the name of a macro variable within double quotation marks but without an ampersand
the name of a DATA step character variable, specified with no quotation marks, which contains a macro variable name
a character expression that constructs a macro variable name

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