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

I'm learning SAS and I'm looking for ways to make my code better. For assignments, I start by pulling the files I need from a public library into my work library.  Right now, I am writing out a DATA SET step for each file pull. For example, if I know I need to work on three files, I start my assignment with the code below: 

 

data dataset1;
    set public.dataset1;
run;

 

data dataset2;
    set public.dataset2;
run;

 

data dataset3;
    set public.dataset3;
run;

 

Is there a way to simplify this? And what are your thoughts on best practices, if any? 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use PROC COPY.

proc copy inlib=public outlib=work;
  select dataset1 dataset2 dataset3 ;
run;

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

Since you specifically ask about "best practices", one has to ask why you want to do this. You can do a PROC MEANS (for example) or any other PROC on public.dataset1, just as you could on work.dataset1. The advantage of doing it on public.dataset1 is that it is one less step to program for each data set of interest. So I am asking you to consider simplifying your work flow by leaving the data sets in library PUBLIC. In your LIBNAME PUBLIC statement, you can add option ACCESS=READONLY so that you don't accidentally overwrite the data sets in PUBLIC. These are "best practices" in my opinion.

 

Nevertheless, you may have valid reasons to do this which you didn't state, in which case PROC COPY will do what you want, in bulk, all (or selected) datasets in PUBLIC get copied to WORK by writing one PROC COPY.

--
Paige Miller
jlsagisi
Calcite | Level 5
Great question. I was told to do this so I don't accidentally make changes to a "master copy" in the public folder (which is used by more than person). And, I definitely see what you're saying. I was able to use PROC COPY. Thank you.
Tom
Super User Tom
Super User

@jlsagisi wrote:
Great question. I was told to do this so I don't accidentally make changes to a "master copy" in the public folder (which is used by more than person). And, I definitely see what you're saying. I was able to use PROC COPY. Thank you.

Just make sure to define PUBLIC as readonly and you will not be able to change them.

libname public 'path' access=readonly;
ballardw
Super User

@jlsagisi wrote:
Great question. I was told to do this so I don't accidentally make changes to a "master copy" in the public folder (which is used by more than person). And, I definitely see what you're saying. I was able to use PROC COPY. Thank you.

Depending on where your Public library is defined permissions or options should prevent that.

If you execute a LIBNAME statement you can add the option Access=readonly and then you cannot modify any of the data sets, intentionally or accidentally.

The statement would look something like:

 

libname mylib "<path to the library>" access=readonly;

ballardw
Super User

In addition to @PaigeMiller's suggestion I would say that if your are going to want to use those data sets in another SAS session that you should copy them to permanent library instead of Work. When you close SAS then your work library is emptied (barring some interesting settings) and if you need the data then you start from scratch. If you create a local permanent library then you just make sure that library is available and you're good to go.

 

Of do you need to have new versions because the public data changes?

Tom
Super User Tom
Super User

Use PROC COPY.

proc copy inlib=public outlib=work;
  select dataset1 dataset2 dataset3 ;
run;
PaigeMiller
Diamond | Level 26

@jlsagisi 

Might I suggest that you go back to your ORIGINAL post and correct the spelling of "public" in the Subject line? (Or perhaps a moderator can do this). Thanks!

--
Paige Miller
ballardw
Super User

@PaigeMiller wrote:

@jlsagisi 

Might I suggest that you go back to your ORIGINAL post and correct the spelling of "public" in the Subject line? (Or perhaps a moderator can do this). Thanks!


Done

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
  • 755 views
  • 1 like
  • 4 in conversation