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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@ssv

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;

View solution in original post

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

If you keep the same name, you can use proc copy (and a select statement if needed).

 

ssv
Fluorite | Level 6 ssv
Fluorite | Level 6

Thank you so much for your response. It worked 🙂

Patrick
Opal | Level 21

@ssv

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;
ssv
Fluorite | Level 6 ssv
Fluorite | Level 6

Thank you so much for your response. It worked 🙂

Reeza
Super User
PROC DATASETS/COPY moves the data over in chunks, a data step copies the data line by line. This means PROC COPY is significantly faster as well.
ssv
Fluorite | Level 6 ssv
Fluorite | Level 6
Thank you so much for your response. It worked out 🙂

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 1630 views
  • 8 likes
  • 4 in conversation