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

data work.TEST_TABLE;
input libname:$32. tablename:$32. to_libname:$32. to_tablename:$32.;
datalines;
sashelp class work copied_class
sashelp cars work copied_cars
;
run;

 

Hi!

 

I want to create a macro that reads from a table and copies it according to the specified conditions. So it reads from which lib to which lib and which table to copy. Could you help put this into practice? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Unless you have a good reason why you want a macro to do this, Call Execute is a nice tool to create data driven code.

 

Try this

 

data work.TEST_TABLE;
input libname:$32. tablename:$32. to_libname:$32. to_tablename:$32.;
datalines;
sashelp class work copied_class
sashelp cars work copied_cars
;
run;

data _null_;
   set test_table;
   call execute
   (compbl(cat(
   "data ", catx('.', to_libname, to_tablename), ";
       set ", catx('.', libname, tablename),";
   run;"
    )));
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Unless you have a good reason why you want a macro to do this, Call Execute is a nice tool to create data driven code.

 

Try this

 

data work.TEST_TABLE;
input libname:$32. tablename:$32. to_libname:$32. to_tablename:$32.;
datalines;
sashelp class work copied_class
sashelp cars work copied_cars
;
run;

data _null_;
   set test_table;
   call execute
   (compbl(cat(
   "data ", catx('.', to_libname, to_tablename), ";
       set ", catx('.', libname, tablename),";
   run;"
    )));
run;
ger15xxhcker
Quartz | Level 8

Can you help me with one more thing?

There are two tables. One of them is what board to copy and where you helped. The other step would be to overwrite or clear certain fields with a default value based on another table.

So if the value of to_archive is Y and the value of the procedure field is default_value then it should be overwritten with the value written there and if the value of to_empty is then emptied that field.

 

data work.to_archive_and_deperson;
input libname:$32.  tablename:$32. to_libname:$32. to_tablename:$32.;
datalines;
sashelp class work copied_class
sashelp cars work copied_cars
;
run;

data work.columns_to_deperson;
infile datalines delimiter=',';
input sas_libname:$32. sas_table_name:$32. column_name:$32.  to_archeve:$1. procedure:$32. default_value:$32.;
datalines;
sashelp,class,name,Y,default_value,XXXX
sashelp,cars,modell,N, ,  
sashelp,cars,make,Y,to_empty,,
;
run;

Thanks a lot!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 495 views
  • 2 likes
  • 2 in conversation