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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 2046 views
  • 4 likes
  • 5 in conversation