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
PeterClemmensen
Tourmaline | Level 20

@ManuelaVila I moved this thread to the IMl forum.

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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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