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

Hello community,

I've tried several different ways in an attempt to pass the location of the excel file to this macro.

But I keep getting nothing. My logs just showed the code I rant. So I started using option symbolgen and mlogic

to see if that would produce something for me. It did. It at least gave me the value of &path.

Also I did hard code this and it worked perfectly fine. 

PLEASE HELP AND THANKS IN ADVANCE

I'm using Base SAS 9.4

 

options symbolgen mlogic;
%Let path = C:\mysdtm\SDTM_METADATA.xlsx;
%put NOTE: &path;
%macro make_blank_dataset(metadatafile=,dataset=);
proc import
datafile="&metadatafile"
out=_temp

options symbolgen mlogic;
%Let path = C:\mysdtm\SDTM_METADATA.xlsx;
%put NOTE: &path;
%macro make_empty_dataset(metadatafile=,dataset=);
    proc import 
        datafile="&metadatafile"
        out=_temp 
        dbms=excelcs
        replace;
        sheet="VARIABLE_METADATA";
    run;
%mend make_empty_dataset;
%macro make_empty_dataset(path, AE);


dbms=excelcs
replace;
sheet="VARIABLE_METADATA";
run;
%mend make_empty_dataset;
%macro make_blank_dataset(path, AE);

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Instead of 

 

%macro make_empty_dataset(path, AE);

 

I think you need

 

%make_empty_dataset(metadatafile=&path, dataset=AE)

Although nowhere have you specified what AE is, and maccro variable &DATASET is not used in the macro.

 

 

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Instead of 

 

%macro make_empty_dataset(path, AE);

 

I think you need

 

%make_empty_dataset(metadatafile=&path, dataset=AE)

Although nowhere have you specified what AE is, and maccro variable &DATASET is not used in the macro.

 

 

--
Paige Miller
cj9000
Obsidian | Level 7
Thank you, thank you. It's the small things we overlook I guess, like dropping the word %macro and also adding an amper to path.
So this is just a snippet of a larger program. I just cut it off at the beginning in an attempt to get the connection working. AE is the adverse event dataset name. Eventually I will have this iterate all of the domain metadata. Thanks again.
Tom
Super User Tom
Super User

You use the %MACRO statement when DEFINING a macro.  Then CALLING the macro you just use its name.

Your log is not showing anything because it is still waiting for the %MEND statement to mark the end of the new definition for the macro.

 

To reference the VALUE or a macro variable you use & before the name of the macro variable.

 

When you define a macro parameter using = then it is considered a NAMED parameter instead of POSITIONAL parameter. You cannot pass value to named parameters without including the name in the macro call. (although you can pass values for positional parameters by including the name).

 

So your call should look like:

 

%make_empty_dataset(metadatafile=&path, dataset=AE)

Note that your macro never uses the value of the dataset parameter anywhere.  Perhaps you want to change this section of the macro definition?

  out=&dataset

 

cj9000
Obsidian | Level 7
Thank you Tom for explaining this in industry terminology. Question: So when using a positional parameter I would just drop the = sign in both the Macro statement and the Macro call?
Tom
Super User Tom
Super User

Pretty much. 

 

When you define the macro if the parameter name is NOT followed by the = then you CAN call it by position.  When the parameter IS followed by the = then use MUST call it by name. You must define any positional parameters before any named parameters. 

 

When calling the macro you can pass the positional parameter values in without their names, just by the position in the call.  But you can also call them by their name if you want.  Note that when calling the macro any values passed by position must appear before any named values. Also when passing values by name the order that the parameters appear in the call does not need to match the order that the parameters were defined in the %MACRO statement.

 

.

cj9000
Obsidian | Level 7
Good stuff to know, thank you.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Discussion stats
  • 6 replies
  • 10996 views
  • 0 likes
  • 3 in conversation