Hello,
I have a set of tables in two libraries. I need to create these tables in a work library.
So basically let's assume I have the following:
lib1.table_a
lib1.table_b and so on
lib2.table_a
lib2.table_b ...
Desired Output:
Work.Lib1_table_a
Work.Lib1_table_b
Work.Lib2_table_a
Work.Lib2_table_b
what have i done so far is:
%let Lib = Lib1.;
%let table = table_a;
data &table;
set &Lib&table;
run;
What I need to do is:
I am not fluent in the loop subject so plain language would be highly appreciated.
Thank you
Regards
@aggers wrote:
Desired Output:
Work.Lib1_table_a
Work.Lib1_table_b
Work.Lib2_table_a
Work.Lib2_table_b
How about this, it's not exactly the same as above, but it ought to serve the same purpose, with a lot less work, no macros or loops. LIB1 gets copied into WORK, and LIB2 gets copied into WORK2.
options dlcreatedir;
libname work2 "%sysfunc(getoption(WORK))/%sysfunc(uuidgen())" access=temp;
proc copy in=lib1 out=work mtype=DATA;
run;
proc copy in=lib2 out=work2 mtype=DATA;
run;
Do you want all data sets from the spcified libraries to be copied?
Yes, and I have dozens of tables. The exercise needs to include %let statement and "do while".
@aggers wrote:
Hello,
I have a set of tables in two libraries. I need to create these tables in a work library.
So basically let's assume I have the following:
lib1.table_a
lib1.table_b and so on
lib2.table_a
lib2.table_b ...
Desired Output:
Work.Lib1_table_a
Work.Lib1_table_b
Work.Lib2_table_a
Work.Lib2_table_b
what have i done so far is:
%let Lib = Lib1.;
%let table = table_a;
data &table;
set &Lib&table;run;
What I need to do is:
- Macro should simply read the data from ANY DATASET in source library and then output the TARGET table which is an exact copy of the SOURCE table, but its name was passed using %let statement (which I think I've done)
- Macro that includes “do while” statement application. The program should produce output when %let statement is set to YES, otherwise it should output error message in the log.
I am not fluent in the loop subject so plain language would be highly appreciated.
PROC COPY does this without macros, without loops and without DO WHILE.
proc copy in=lib1 out=work mtype=DATA;
run;
Why?
@aggers wrote:
it's a part of an exercise I have to do. I know there are many ways of completing this, but I need to use %let and "do while" statements to complete my task.
Any WHILE or UNTIL loop requires 1) what to loop over, 2) an incrementing value rule and 3) an explicit stopping rule. Which values are you looping over? It is not clear exactly clear what the "variable" or "values" would be: 1 and 2 above.
You also have not supplied any idea of the stopping rule.
I will also say, besides other comments about use the correct tool for a task such as Proc Copy or Datasets in this case, that macro While and Until loops are often much harder to manage, at least in my experience then iterated loops over a known list of values.
@aggers wrote:
it's a part of an exercise I have to do. I know there are many ways of completing this, but I need to use %let and "do while" statements to complete my task.
So its a homework assignment? Usually, we expect you to write the code as far as you can go, and then if it's not working, show us the code and the LOG and we can help you get beyond that point.
/*concatenate the two libnames to one*/
libname comb (lib1 lib2);
/*then copy the combined libname to work using proc datasets or proc copy suggested by Paigemiller*/
proc datasets library=comb;
copy out=work;
run;
@aggers wrote:
Desired Output:
Work.Lib1_table_a
Work.Lib1_table_b
Work.Lib2_table_a
Work.Lib2_table_b
How about this, it's not exactly the same as above, but it ought to serve the same purpose, with a lot less work, no macros or loops. LIB1 gets copied into WORK, and LIB2 gets copied into WORK2.
options dlcreatedir;
libname work2 "%sysfunc(getoption(WORK))/%sysfunc(uuidgen())" access=temp;
proc copy in=lib1 out=work mtype=DATA;
run;
proc copy in=lib2 out=work2 mtype=DATA;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.