Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:16:51+00:00 2026-06-12T23:16:51+00:00

In SAS there’s an method of creating Library (using LIBNAME). This is helpful as

  • 0

In SAS there’s an method of creating Library (using LIBNAME). This is helpful as when we have to do long data processing, we don’t change always the dataset name. So, if we want to use a dataset again, without changing the name, we can put in a library. So, even if the dataset name are same, but since they are in different libraries, we can work on them together.

My question is there any such option in R that can create Library (or separate folder within R) so that we can save our data there?

Here’s the example:

Suppose I’ve a dataset "dat1". I summarize variables in dat1 var1 & var2 for var3.

proc summary data=dat1 nway missing;
  var var1 var2;
  class var3;
  output out=tmp.dat1 (drop = _freq_ _type_) sum = ;
  run;

Then I merged dat1 with dat2, which is another dataset.Both dat1 & dat2 has common variable var3, with which I merged. I created new dataset dat1 again.

proc sql;
   create table dat1 as
   select a.*,b.*
   from dat1 a left join tmp.dat2 b
   on a.var3=b.var3;
  quit;

Now, I’m again summarizing dataset dat1 after merging to check if the values of var1 & var 2 remain the same before & after merging.

proc summary data=dat1 nway missing;
  var var1 var2;
  class var3;
  output out=tmp1.dat1 (drop = _freq_ _type_) sum = ;
  run;

The equivalent code in R will be

dat3 <- ddply(dat1,
              .(var3),
              summarise,
              var1 = sum(var1,na.rm=TRUE),
              var2 = sum(var2,na.rm=TRUE))

dat1 <- sqldf("select a.*,b.* 
                 from dat1 a 
                      left join dat2 b 
                             on a.var3=b.var3")

dat4 <- ddply(dat1,
              .(var3),
              summarise,
              var1 = sum(var1,na.rm=TRUE),
              var2 = sum(var2,na.rm=TRUE))

In case of SAS I used just 2 dataset name. But in case of R, I’m using 4 dataset name. So, if I’m writing 4000 line code for data processing, having too many dataset name sometimes become overwhelming. In sas it became easy to have same dataset name as I’m using 2 libraries tmp, tmp1 other than the default work library.

In SAS, library is defined as:

LIBNAME tmp "directory_path\folder_name";

In this folder, dat1 will be stored.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:16:52+00:00Added an answer on June 12, 2026 at 11:16 pm

    Here is an example using the SOAR package and named environments

    To quote from the vignette

    Objects need not be always held in memory. The function save may be used to save objects on the disc in a file, typically with an .RData extension. The objects may then be removed from memory and later recalled explicitly with the load function.

    The SOAR package provides simple way to store objects on the disc, but in such a way that they remain visible on the search path as promises, that is, if and when an object is needed again it is automatically loaded into memory. It uses the same lazy loading mechanism as packages, but the functionality provided here is more dynamic and exible

    It will be useful to read the whole vignette

    library(SOAR)
    library(plyr)
    library(sqldf)
    set.seed(1)
    
    # create some dummy data create a named envirment
    tmp <- new.env(parent = .GlobalEnv)
    dat1 <- data.frame(var1 = rnorm(50),
                       var2 = sample(50, replace = TRUE),
                       var3 = sample(letters[1:5], 50, replace = TRUE))
    
    tmp$dat1 <- ddply(dat1, .(var3), summarise,
                      var1 = sum(var1, na.rm = TRUE), 
                      var2 = sum(var2, na.rm = TRUE))
    
    tmp$dat2 <- data.frame(Var3 = sample(letters[1:5], 20, replace = TRUE), 
                           Var4 = 1:20)
    
    # store as a SOAR cached object (on disc)
    Store(tmp, lib = "tmp")
    
    # replace dat1 within the global enviroment using sqldf create a new
    # environment to work in with the correct version of dat1 and dat2
    sqlenv <- tmp
    sqlenv$dat1 <- dat1
    
    dat1 <- sqldf("select a.*,b.* from dat1 a left join dat2 b on a.var3=b.var3", 
                  envir = sqlenv)
    
    # create a new named enviroment tmp1
    tmp1 <- new.env(parent = .GlobalEnv)
    
    tmp1$dat1 <- ddply(dat1, .(var3), summarise, 
                       var1 = sum(var1, na.rm = TRUE), 
                       var2 = sum(var2, na.rm = TRUE))
    
    # store using a SOAR cache
    Store(tmp1, lib = "tmp")
    
    
    tmp1$dat1
    
    ##   var3   var1 var2
    ## 1    a  1.336  378
    ## 2    b  8.514 1974
    ## 3    c  5.795  624
    ## 4    d -8.828  936
    ## 5    e 20.846 1490
    
    tmp$dat1
    
    ##   var3    var1 var2
    ## 1    a  0.4454  126
    ## 2    b  1.4190  329
    ## 3    c  1.9316  208
    ## 4    d -2.9427  312
    ## 5    e  4.1691  298
    

    I’m not sure you should expect tmp1$dat1 and tmp$dat1 to be identical (given my example anyway)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are gov't data files: http://www.cdc.gov/EpiInfo/ Available in this weird SAS format. How can
Using SAS's Proc SQL, is there a way to insert records from a SAS
I'm using SAS Enterprise Guide 5.1 and I have a project made of 4
I'm using SAS 9.1.3 to call a macro in a DATA step, but the
I am from DW/BI background using SAS for many years now I have task
This question is related to Tools for matching name/address data . There is a
Is there a way to check how many observations are in a SAS data
I have a SAS dataset that looks like this: var _12 _41 _17 12
I'm using SAS 9.2 on OpenVMS to connect to an external data source over
Does anyone have experience using a third-party unit testing framework for SAS such as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.