BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ManuelaVila
Fluorite | Level 6

Hi im trying to import to sas some tables that are in R named: table_1 , table_2 , table_3 etc.

I need to do this with a loop because the number of tables will depend of de number of rows of another table (table_w). i imagine it would be something like :

call ImportDataSetFromR("table_w","table_w"); 
do i=1 to nrow(table_w); 
call ImportDataSetFromR("table_"&i,"table_"&i); end;

but when i run it it has no errors but the are no tables in work.

thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

That syntax is not valid. There is no macro variable named 'i', so &i is null.

 

Also, you are importing table_w as a data set, so the expression nrow(table_a) equals 0. Maybe you meant to import it as a matrix?

 

I don't know what names you want to read, but here is some sample code that might help you figure it out.

 

proc iml;
table_w = {'A', 'My_results', 'More_results'};
do i=1 to nrow(table_w); 
   dsName = strip(table_w[i]);
   print i dsName;
   *call ImportDataSetFromR(dsName,dsName); /* uncomment when ready */
end;

/* or if the tables are named table_w1, table_w2, etc */
do i=1 to nrow(table_w); 
   dsName = "table_w" + strip(char(i));
   print i dsName;
   *call ImportDataSetFromR(dsName,dsName); /* uncomment when ready */ 
end;

 

 

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

That syntax is not valid. There is no macro variable named 'i', so &i is null.

 

Also, you are importing table_w as a data set, so the expression nrow(table_a) equals 0. Maybe you meant to import it as a matrix?

 

I don't know what names you want to read, but here is some sample code that might help you figure it out.

 

proc iml;
table_w = {'A', 'My_results', 'More_results'};
do i=1 to nrow(table_w); 
   dsName = strip(table_w[i]);
   print i dsName;
   *call ImportDataSetFromR(dsName,dsName); /* uncomment when ready */
end;

/* or if the tables are named table_w1, table_w2, etc */
do i=1 to nrow(table_w); 
   dsName = "table_w" + strip(char(i));
   print i dsName;
   *call ImportDataSetFromR(dsName,dsName); /* uncomment when ready */ 
end;

 

 

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!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 614 views
  • 1 like
  • 3 in conversation