BookmarkSubscribeRSS Feed
3 REPLIES 3
Samiresh
Calcite | Level 5

I have a dataset "tablenames" with the list of table names and the row count for each table. I need to run an iteration loop for SYMPUT function such that each row values is parsed to 2 global variables. These 2 global variables containing the value of the table name and row count is used in another macro program. 

 

I am not able to pass multiple iterations of values to SYMPUT function as it takes only the final row data. Try many work arounds but all ended up with errors. Please find the below structure of code i am using 

 

Here in the below code, i tried to copy table contents into 2 individual global  arrays and tried to use them in the do - while loop. But the code didn't execute successfully

 

Code

 

proc sql;
select filename into :file_name from function_call order by row_num;
run;

 

proc sql;
select record_count into :record_count from function_call order by row_num;
run;

 

%do i=1 %to &max_size. %by 1;
call symput('scenario_us',trim(scenarios[&i]));
%put ETL-NOTE: scenario_us = &scenario_us;

run;
%end;

Tom
Super User Tom
Super User

A macro variable can only contain one value at a time.  That is why you see only the results of the last assignment.

 

Perhaps you should just leave the data in the dataset and drive your process using the dataset instead of macro variables.

 

What are you actually trying to do? Before you start using macro variables or macro code to generate code you need to know what code you want to generate.

 

Show two rows of the data and what code you want to generate from those two rows. 

ballardw
Super User

@Samiresh wrote:

I have a dataset "tablenames" with the list of table names and the row count for each table. I need to run an iteration loop for SYMPUT function such that each row values is parsed to 2 global variables. These 2 global variables containing the value of the table name and row count is used in another macro program. 

 

I am not able to pass multiple iterations of values to SYMPUT function as it takes only the final row data. Try many work arounds but all ended up with errors. Please find the below structure of code i am using 

 

Here in the below code, i tried to copy table contents into 2 individual global  arrays and tried to use them in the do - while loop. But the code didn't execute successfully

 

Code

 

proc sql;
select filename into :file_name from function_call order by row_num;
run;

 

proc sql;
select record_count into :record_count from function_call order by row_num;
run;

 

%do i=1 %to &max_size. %by 1;
call symput('scenario_us',trim(scenarios[&i]));
%put ETL-NOTE: scenario_us = &scenario_us;

run;
%end;


Call symput is usually in a data step though I guess you might use it in a Proc SQL Call. However, your call symput is in neither. The use of

scenarios[&i]

requires an array, which means it belongs in a data step and you very clearly do not have a data step or an array definition.

 

Just how many errors do you get in the log with this attempted code?

 

If you provide a small example data set and what the actual content of your macro variables is supposed to be we may be able to help with that. But sticking multiple values into a single variable almost always is followed by pulling them out again.

Note that the result of this code

 

proc sql;
select filename into :file_name from function_call order by row_num;
quit;

is going to place the first, by alphabet value within row_num, filename. ONE filename only. So I am not sure what relation this has to placing multiple values into anything since you do not use the created $filename macro variable.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 701 views
  • 0 likes
  • 3 in conversation