BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yus03590
Calcite | Level 5
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!

 

1 ACCEPTED SOLUTION
4 REPLIES 4
Reeza
Super User

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!

 


 

novinosrin
Tourmaline | Level 20

%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;
ruchi11dec
Obsidian | Level 7

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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