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

or

 

Data perm.x;

Set y;

Run;

 

Data y;

Set perm.x;

Run;

 

What does this accomplish?

 

I've also seen it done without the libref...

 

TIA

p.s. first post

1 ACCEPTED SOLUTION
8 REPLIES 8
SASKiwi
PROC Star
* Copies a SAS dataset y from the SAS WORK library to the PERM (permanent) library and calling it x.; 
Data perm.x;
Set y;
Run;

* Copies a SAS dataset x from the SAS PERM library to the SAS WORK library and calling it y.; 
Data y;
Set perm.x;
Run;
Tacoma66
Calcite | Level 5

Thanks for the reply.

 

Yes, those are the basics,

 

but why why would a programmer save x from y and then turn around and create a new y (same name) from the x you just created.

 

y is already in the work library...

 

I've seen this done in several legacy programs I am working on, and I don't know why the programmer is doing it. I've seen it with work lib only sets.

SASKiwi
PROC Star

If these steps are part of a bigger process then we would need to see that process to understand if the steps have a purpose or are completely redundant.

 

In isolation I agree with @ChrisNZ that they don't make sense.

Tacoma66
Calcite | Level 5

Nothing happens in the sets, so what happens before or after is irrelevant.

 

They are creating a set from something they have and then overwriting the original with what they created.

 

My head literally does a double take movement every time I see it, like a glitch.

SASKiwi
PROC Star

I agree, there is no processing logic in the posted DATA steps but copying a data set into a permanent SAS library could be a legitimate step as the dataset might be used in another program. On the other hand if the datasets are not subsequently used anywhere else then these steps should be removed to avoid confusion.

ballardw
Super User

@Tacoma66 wrote:

Thanks for the reply.

 

Yes, those are the basics,

 

but why why would a programmer save x from y and then turn around and create a new y (same name) from the x you just created.

 

y is already in the work library...

 

I've seen this done in several legacy programs I am working on, and I don't know why the programmer is doing it. I've seen it with work lib only sets.


There are people out there that create a new data set every time they do a calculation or add a variable instead of moving the code (once tested) to an earlier data step.

 

You will find dozens of examples on this forum of people with code like:

data temp;
   set sashelp.class;
run;

proc print data=temp;
run;

instead of

Proc print data=sashelp.class;
run;

Normally I consider it behavior of new programmers that just haven't learned better. There are some things I see that make me think there are class Instructors that just never learned better because of some recurring code with same named variables/datasets and code like you are asking about that we see here every fall and spring.

FreelanceReinh
Jade | Level 19

Hello @Tacoma66 (and welcome to the SAS Support Communities, btw :-)),


@Tacoma66 wrote:

Data perm.x;

Set y;

Run;

 

Data y;

Set perm.x;

Run;


Maybe those "legacy programs" contain (possibly incomplete) draft code, e.g.:

/* Friday, 18 Oct 2019, 5:30 PM: save draft of dataset Y in a permanent library, then shut down the computer */

Data perm.x;
Set y;
Run;

/* Monday, 21 Oct 2019, 8:00 AM: continue working on Y, based on the latest draft */

Data y;
Set perm.x;
Run;

@Tacoma66 wrote:

I've also seen it done without the libref...


Again, with hypothetical comments added:

/* Create a backup copy of a preliminary version of dataset Y */

Data x;
Set y;
Run;

/* Continue working on Y */
/* ... */

/* Realize that most recent changes were wrong, delete embarrassingly flawed code, restore previous version of Y */

Data y;
Set x;
Run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 457 views
  • 3 likes
  • 5 in conversation