BookmarkSubscribeRSS Feed
topkatz
Obsidian | Level 7
(originally posted in SAS-L, Thursday, August 27th)

Hi.

I want to move a data set to a new library and give it a new name, but
keep the original date information. I tried the following in SAS 9.1.3 on
Windows XP:

proc datasets nolist library=lib2;
copy in=lib1 out=lib2 move datecopy;
select ds1;
rename ds1=ds2;
run;

I did move lib1.ds1 to lib2.ds2 this way, but it had new date information,
both within SAS and Windows. And it wasn't the rename operation that
changed the date information, because I tried running the copy and change
separately, and the date information was changed only by the copy
command. Should the datecopy option do what I wanted it to do? If not,
is there a SAS-specific way to do this (rather than using operating system specific commands)?

Thanks!

-- TMK --
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Check your SAS log and your PROC DATASETS syntax used - here is the error message I expect you received:

x rename ds1=ds2;
ERROR: There is no data set to modify.


The CHANGE statement is what you want to use, not the RENAME statement.

Scott Barry
SBBWorks, Inc.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Also, I was successful using the datecopy option to preserve the original date of a copied file (on SAS 9.1.3 SP4, Windows XP) -- the processing was successful with copying SASHELP.class to WORK (with datecopy but not move), and then again COPY from lib1 to lib2 with options move and datecopy. However, a new proc datasets was needed to effect the "change" against the lib2 data library - you had lib=lib1 coded though (all functions attempted in a single proc datasets, which would not work.

Scott Barry
SBBWorks, Inc.
topkatz
Obsidian | Level 7
Hi Scott. Thank you for the follow-up. I didn't understand your description of what you did. Could you please show me your actual code that preserved the original date information after a move and rename (change)?

-- TMK --
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Just re-tested with the code below (very similar to your code, excepting using SASHELP.CLASS) and the SAS-reported (not Windows) date information (found in PROC CONTENTS member level info) reflects the original SASHELP.CLASS information, as expected (SAS 9.1.3 SP4, Windows):

options nocenter;
libname lib1 'c:\temp\sas';
libname lib2 'c:\temp\sas\other';
* start with empty SAS data library references. ;
proc datasets kill nolist lib=lib1;
run;
proc datasets kill nolist lib=lib2;
run;
proc datasets nolist library=lib2;
* copy the SAS sample member. ;
copy datecopy in=sashelp out=lib1;
select class;
* CONTENTS will verify the CREATED/MODIFIED date. ;
contents data=lib1.class;
* now COPY (move) and generate CONTENTS. ;
copy in=lib1 out=lib2 move datecopy;
select class;
change class=myclass;
contents data=lib2.myclass;
run;



Scott Barry
SBBWorks, Inc.
topkatz
Obsidian | Level 7
Ah, I see... so the SAS "Last Modified" information doesn't necessarily agree with the Windows "Date Modified" information. If you remove the "nolist" option and do something like the following:

proc datasets library=lib2;
contents data=myclass;
run;
quit;

the "Last Modified" entry in the log (and "Date Modified" entry in Windows Explorer) probably will be more recent than the "Last Modified" entry in the contents output listing. I see that you remarked on this fact in the preface to your code.

So, is there a way to preserve the Windows date information through SAS itself, or does that require the use of operating system specific commands (issued, e.g., via the "X" statement)?

Thanks!

-- TMK --
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
I expect there is no SAS-control to effect the Windows date.

Scott Barry
SBBWorks, Inc.
topkatz
Obsidian | Level 7
Hi Scott.

Thank you for responding. Yes, you caught an error in my transcription. I actually did use "change" rather than "rename" in my code, and I didn't get an error message; the move and rename (well, change) worked perfectly, but it didn't preserve the date of the original file, which is what I'd like to do, if possible. So the correct move and rename code is:

proc datasets nolist library=lib2;
copy in=lib1 out=lib2 move datecopy;
select ds1;
change ds1=ds2;
run;

but the datecopy option, which is described as follows in the online doc:

"copies the SAS internal date and time when the SAS file was created and the date and time when it was last modified to the resulting copy of the file. Note that the operating environment date and time are not preserved."

appears to have no effect. I think that last sentence in the description is an admission that the datecopy option isn't designed to do what I wanted. But then I don't even understand what it's good for. There is a remark in the doc that the date can be manually altered using the DTC= option on the MODIFY statement, so maybe I have to see if I can capture the original date info and then reassign it after the move. Honestly, that seems unnecessarily complicated to me, but I'll see if I can get it to work.

-- TMK --

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
  • 7 replies
  • 2095 views
  • 0 likes
  • 2 in conversation