Hi there!
I have to import few datasets(sas7bdat) from external source into SAS. so I have used libname statement to address those datasets location. Is there any way to copy each of these datasets in to new datasets conditionally?
FOR EXAMPLE: I have 5 sas datasets (a, b, c, d, e with extension .sas7bdat) in C:\Users\Desktop\XYZ folder. i have used this LIBNAME Statement to import them into sas.
LIBNAME IMPORTED "C:\Users\Desktop\XYZ";
I want to copy these datasets(A, B, C, D, E) into 5 NEW datasets(P, Q, R, S, T) conditionally, which means I want to copy dataset A into P, B into Q, C into R, D into S, E into T.
I am doing this:
Data P;
set A;
run;
data Q;
set B;
run;
But is there any possibility of reducing the code? instead of using the set statement and repeating the code again and again is there any other way?
Your response is Highly Appreciated.
Thank you.
Copy the files into a new folder. Keeping source and target clearly separated is "cleaner" and it also allows you to use Proc Datasets.
options dlcreatedir;
libname source 'c:\temp\source';
data source.a;
set sashelp.class;
run;
data source.b;
set sashelp.class;
run;
libname target 'c:\temp\target';
proc datasets lib=target nolist;
delete p q;
run;
copy in=source out=target;
select a b;
run;
change a=p b=q;
run;
quit;
If you keep the same name, you can use proc copy (and a select statement if needed).
Thank you so much for your response. It worked 🙂
Copy the files into a new folder. Keeping source and target clearly separated is "cleaner" and it also allows you to use Proc Datasets.
options dlcreatedir;
libname source 'c:\temp\source';
data source.a;
set sashelp.class;
run;
data source.b;
set sashelp.class;
run;
libname target 'c:\temp\target';
proc datasets lib=target nolist;
delete p q;
run;
copy in=source out=target;
select a b;
run;
change a=p b=q;
run;
quit;
Thank you so much for your response. It worked 🙂
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.