Hello,
I have a dataset ds22 which lists the datasets that need to be copied over:
data ds22;
dataset="DM";
output;
dataset="SC";
output;
run;
The syntax used to copy them from f_ to o_ is:
data chk_;
set ds22;
call execute("proc copy in= f_ out=o_; select "||compress(dataset)||"; run;");
run;
Can someone help me understand how ||compress(dataset)|| works here to read the datasets called in ds22 individually?
It's calling PROC COPY for each data set.
Change the code slightly to see the generated code more easily by adding a variable (STR) to hold the code.
Then view this CHK_ data set to see the code generated (note that I commented out the CALL EXECUTE so it won't run it in this one.
CALL EXECUTE simply executes code snippets passed to it. The data step builds that statement dynamically using the "dataset" variable in the ds22 dataset.
data chk_;
set ds22;
str = ""proc copy in= f_ out=o_; select "||compress(dataset)||"; run;";
*call execute(str);
run;
proc print data=chk_ (obs=5);
var str;
run;
@Tommer wrote:
Hello,I have a dataset ds22 which lists the datasets that need to be copied over:
data ds22;
dataset="DM";
output;
dataset="SC";
output;
run;
The syntax used to copy them from f_ to o_ is:
data chk_;
set ds22;
call execute("proc copy in= f_ out=o_; select "||compress(dataset)||"; run;");
run;
Can someone help me understand how ||compress(dataset)|| works here to read the datasets called in ds22 individually?
It's calling PROC COPY for each data set.
Change the code slightly to see the generated code more easily by adding a variable (STR) to hold the code.
Then view this CHK_ data set to see the code generated (note that I commented out the CALL EXECUTE so it won't run it in this one.
CALL EXECUTE simply executes code snippets passed to it. The data step builds that statement dynamically using the "dataset" variable in the ds22 dataset.
data chk_;
set ds22;
str = ""proc copy in= f_ out=o_; select "||compress(dataset)||"; run;";
*call execute(str);
run;
proc print data=chk_ (obs=5);
var str;
run;
@Tommer wrote:
Hello,I have a dataset ds22 which lists the datasets that need to be copied over:
data ds22;
dataset="DM";
output;
dataset="SC";
output;
run;
The syntax used to copy them from f_ to o_ is:
data chk_;
set ds22;
call execute("proc copy in= f_ out=o_; select "||compress(dataset)||"; run;");
run;
Can someone help me understand how ||compress(dataset)|| works here to read the datasets called in ds22 individually?
@Tommer wrote:
Thank you Reeza!
I could not find any documentation on what --- select "||compress(dataset)||" does or how it works. I am only aware of pipe character for concatenation. Would you be able to provide any more info on how "||compress(dataset)||" reads as DM; SC etc?
I don't understand why that is the part that is confusing. Those are concatenation operators. The code is just placing the name of the dataset taken from the dataset variable DATASET in between two text strings.
Perhaps adding more white space will make it clearer?
call execute(
"proc copy in= f_ out=o_; select "
|| compress(dataset)
|| "; run;"
);
It is the CALL EXECUTION() function call that actually turns the resulting string into executed SAS code.
Since SELECT in PROC COPY accepts a list of dataset, you are better off doing it like this
proc sql noprint;
select dataset into :dsnames separated by " "
from ds22;
quit;
proc copy
in= f_
out=o_
;
select &dsnames.;
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!
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.