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!
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!
%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;
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
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.
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.