BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JohnT
Quartz | Level 8
Hi,
I'm trying to replicate a dataset (refreshed daily) in a library based on whether it's the first of the month or not.
I this I want to use a PROC because it's possible I might change the indexes on the dataset in the future.
data cls (index = (name) );
   set sashelp.class;
run;
proc datasets library = work;
   change cls = cls2; run;
quit;
proc contents data = work.cls2;
run;
data cls3 (index = (name) );
   set cls;
run;

^^
The first two datasteps kind of do what I'm after, but it removes the cls dataset, which I want to retain.

The third datastep was there for me to check that the index was still there after the change (and it was).

The final datastep is my current solution, but I don't really want to essentially recreate the dataset.

I'm running SAS 9.3 using Enterprise Guide 5.1 (5.100.0.12269) Hot fix 7 (32-bit)

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Hi JohnT

You can not copy a SAS Data Set within the same library. However you can use other statements from Proc DATASETS to achieve the same. Have a look at the code below. It will delete an existing CLS2 data set. It then uses the APPEND statement, if the base table is not found, then append will make a copy of the data table and preserve index etc.

data cls (index = (name) label="Original CLS");
   set sashelp.class;
run;

proc datasets library = work;
  delete cls2;
run;
 
append  data=cls base=cls2;
run;
quit;

View solution in original post

4 REPLIES 4
Fugue
Quartz | Level 8

So . . . you want to keep the original dataset (CLS), and you don't need the final dataset (CLS3)?

JohnT
Quartz | Level 8

Sorry I should have been more specific.  Ignore the last two steps, I want CLS and CLS2, they were just for checking and demonstrating my current solution.

data cls (index = (name) );
   set sashelp.class;
run;

proc datasets library = work;
   change cls = cls2; run;
quit;

BrunoMueller
SAS Super FREQ

Hi JohnT

You can not copy a SAS Data Set within the same library. However you can use other statements from Proc DATASETS to achieve the same. Have a look at the code below. It will delete an existing CLS2 data set. It then uses the APPEND statement, if the base table is not found, then append will make a copy of the data table and preserve index etc.

data cls (index = (name) label="Original CLS");
   set sashelp.class;
run;

proc datasets library = work;
  delete cls2;
run;
 
append  data=cls base=cls2;
run;
quit;
JohnT
Quartz | Level 8

Thanks Bruno, that solution works for me.

When I run it using my original solution compared to this one, the times are roughly the same, which is good.  And the fact that the indexes are maintained is exactly what I was after.

Thanks again.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2963 views
  • 1 like
  • 3 in conversation