DATA Step, Macro, Functions and more

Renaming a Dataset

Accepted Solution Solved
Reply
Contributor
Posts: 58
Accepted Solution

Renaming a Dataset

Hi,

I am using SQL to build my datasets and get "warnings" if the name of the modified new dataset is the same as the original dataset.

 

For example:

Dataset Old =

ColA, ColB

 

Dataset New =

ColA, ColB, ColC

(one attribute added)

 

When I call the new dataset the same name as the name of the old dataset, I get a "warning" in the error log.

 

What is a good and simple technique to build my dataset out and so that

1.  I end up with only one dataset and

2.  The result has the name of the Original dataset (even if I have modified the dataset 5 or 6 times) and

2.  I can eliminate all of the warnings?

 

A simple example would help.

(when I research, I find much on renaming attributes but not much on datasets)

 

 

 

 

 

 


Accepted Solutions
Solution
‎08-12-2016 01:28 PM
Respected Advisor
Posts: 3,124

Re: Renaming a Dataset

However NOT recommended, You can opt to data step to get rid of the warning.

data old;
set old;
run;

But if anything goes wrong (e.g. power outage), then you may lost your original data.

 

@Reeza's suggestion is dead on. Name it differently for every change you make, then using Proc dataset to clean the house, doing that guarantee you easy trouble-shoot and better approach of programming.

View solution in original post


All Replies
Contributor
Posts: 58

Renaming a Dataset

I am using SQL to build my datasets and get "warnings" if the name of the modified new dataset is the same as the original dataset.

 

For example:

Dataset Old =

ColA, ColB

 

Dataset New =

ColA, ColB, ColC

(one attribute added)

 

When I call the new dataset the same name as the name of the old dataset, I get a "warning" in the error log.

 

What is a good and simple technique to build my dataset out and so that

1.  I end up with only one dataset and

2.  The result has the name of the Original dataset (even if I have modified the dataset 5 or 6 times) and

2.  I can eliminate all of the warnings?

 

A simple example would help.

(when I research, I find much on renaming attributes but not much on datasets)

 

 

 

 

 

 

Super User
Posts: 17,784

Re: Renaming a Dataset

If your using multiple steps, use names that are unique to each step and then make a final dataset. You can use proc datasets to both remove extra data sets and to rename the final dataset if you'd like. 

Super User
Super User
Posts: 7,397

Re: Renaming a Dataset

The warning you get is telling you that writing to the same dataset that you read from will mean you cannot roll the changes back.  Its an SQL implementation thing.  You can put:

proc sql undopolicy=none;

...

 

That will remove the wraning.  However you may be better off just using datastep language - without seeing your process I can't really advise, but you can merge various datasets and do logic in one step:

data want;
  set old:;
  colc="Hello World";
run;

This would bring in all datasets in work with the prefix old, and create a new variable in the output want dataset.

Solution
‎08-12-2016 01:28 PM
Respected Advisor
Posts: 3,124

Re: Renaming a Dataset

However NOT recommended, You can opt to data step to get rid of the warning.

data old;
set old;
run;

But if anything goes wrong (e.g. power outage), then you may lost your original data.

 

@Reeza's suggestion is dead on. Name it differently for every change you make, then using Proc dataset to clean the house, doing that guarantee you easy trouble-shoot and better approach of programming.

Contributor
Posts: 58

Re: Renaming a Dataset

This Works couple with dropping the Old Dataset.

 

Thank you

 

 

Contributor
Posts: 72

Re: Renaming a Dataset

[ Edited ]

Cody_Devl,

 

I see that you got your answer and I'll bet that you have already implemented it.  Great!

 

I have another idea that will address requirements #2 and #3 that may come in handy some day.  Consider creating Generation Data Groups for the data sets you want to modify.  For example:

 

   proc datasetslibrary=sgflib nolist;

  modify ColA(genmax=10);

  modify ColB(genmax=10);

   run;

    quit;

 

Then, when you modify ColA or ColB, SAS will save the old copies as ColA#001, ColB#001, respectively and keep the modified versions.

 

Don't take my word for it; check it out!

 

 

Best of luck in all your SAS endeavors!

----MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Amazon Author's Page: http://www.amazon.com/Michael-A.-Raithel/e/B001K8GG90/ref=ntt_dp_epwbk_0
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 351 views
  • 3 likes
  • 5 in conversation