macro variable in a DATA Step

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

macro variable in a DATA Step

Hi!  Been a long time since I've used sas.  I apologize if there is a simple solution I am missing.

I'm trying to use macro variables in the set statement of a data step in the following manner:

%let source = "T4_R283"; %let sink = "T3_R230"; data solution_distance_data_single; set "solution_&source._to_&sink." source = &source; sink = &sink; /*distance = sum(edge);*/ /*drop i, j, flow, edge; */ run;

I'm trying to get the set name to be "solution_T4_R283_to_T3_R230" but I get the following error lines in the log:

 

 

254 set "solution_&source._to_&sink."
NOTE: Line generated by the macro variable "SINK".
254 "solution_"T4_R283"_to_"T3_R230"
____________
22
76
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS,
NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 76-322: Syntax error, statement will be ignored.

 

I use periods to delineate the macro variables from the string, what else do I need to do?

 

Thanks!

 


Accepted Solutions
Solution
‎06-11-2018 07:13 PM
Super User
Posts: 10,209

Re: macro variable in a DATA Step

Don't use quotes in the %let.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Posts: 23,663

Re: macro variable in a DATA Step

Are you using named literals?
Is there a specific reason you have the data set name in quotes, it usually isn't unless you're using name literals which would need an N at the end. 

 

Can you show working code - without any macros? Then it's much easier to convert it to a macro.

 


@yus03590 wrote:
Hi!  Been a long time since I've used sas.  I apologize if there is a simple solution I am missing.

I'm trying to use macro variables in the set statement of a data step in the following manner:

%let source = "T4_R283"; %let sink = "T3_R230"; data solution_distance_data_single; set "solution_&source._to_&sink." source = &source; sink = &sink; /*distance = sum(edge);*/ /*drop i, j, flow, edge; */ run;

I'm trying to get the set name to be "solution_T4_R283_to_T3_R230" but I get the following error lines in the log:

 

 

254 set "solution_&source._to_&sink."
NOTE: Line generated by the macro variable "SINK".
254 "solution_"T4_R283"_to_"T3_R230"
____________
22
76
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS,
NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 76-322: Syntax error, statement will be ignored.

 

I use periods to delineate the macro variables from the string, what else do I need to do?

 

Thanks!

 


 

Solution
‎06-11-2018 07:13 PM
Super User
Posts: 10,209

Re: macro variable in a DATA Step

Don't use quotes in the %let.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
PROC Star
Posts: 1,769

Re: macro variable in a DATA Step


%let sink = T3_R230;

data solution_distance_data_single;
set solution_&source._to_&sink.;
source = &source;
sink = "&sink";
/*distance = sum(edge);*/
/*drop i, j, flow, edge; */
run;
Occasional Contributor
Posts: 17

Re: macro variable in a DATA Step

when we use quotes for macro it resolves with the quotes i.e. 

%let a = "sas";

 

%put &=a;

 

a="sas"

 

Hope I made it clear

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 257 views
  • 4 likes
  • 5 in conversation