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 🙂
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.