Write and run SAS programs in your web browser

After Creating a Library, How do I get a Data Set Into It?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

After Creating a Library, How do I get a Data Set Into It?

I created a library called mydata, how do I import data into it so I can start running analyses? (Also, why is this so hard?)  OK, don't need to answer that second question.  I'm using SAS University, so are there some limitations I'm bumping against -- maybe it does not allow data to be read into it?  

 

Thanks.  New User.  Previously used another stats system where this was, well, astonishingly easy, but my school has urged me to use SAS, and so I'm stuck on these basic things.


Accepted Solutions
Solution
2 weeks ago
Grand Advisor
Posts: 17,464

Re: After Creating a Library, How do I get a Data Set Into It?

1. Assign a library - in SAS a library is a directory that you can use to save files. You reference data sets via LIBNAME.DATASETNAME. If you assign the libname by clicking the cabinet icon under Server/Folders you can select an option for the library to stay assigned between sessions of SAS UE. Otherwise you can add the relevant line to your code each time.

 

libname mylib '/folders/myfolders';

2. Import your CSV to SAS dataset.

 

proc import out=mylib.mydata datafile='/folders/myfolders/test.csv' dbms=CSV replace; 
run;

3. Data set is in the library - permanently. If you want to reference it in future programs, assign the libname and go to town.

 

proc print data=mylib.mydata;
run;

4. Your file is ready for analysis in procs

 

proc freq data=mylib.mydata;
table _all_;
run;

proc means data=mylib.mydata;
run;

 

View solution in original post


All Replies
Super Contributor
Posts: 490

Re: After Creating a Library, How do I get a Data Set Into It?

Okay let us suppose that you have a data set and you added it to the shared folder, so you can see it under the "Server Files And Folders" directly or under another folder.

 

Then you can use proc import to import your data to your library like _suppose your new data is CSV file and its name is data1_:

proc import datafile="/folders/myfolders/data1.csv"
     out=mydata.data1
     dbms=csv
     replace;
     getnames=no;
run;

You need to specify your data file name in the datafile parameters. Then specify your library name in the out parameters with the name you choose for your data.

 

Hope that help.

 

Also if you do not like to write the code each time you import new data. You can use import data option in SAS Studio and then edit the code by your library name.

Occasional Contributor
Posts: 6

Re: After Creating a Library, How do I get a Data Set Into It?

Thanks.  When I tried suggested code:

 

 
56 proc import datafile="/folders/myfolders/test.csv"
57 out=test.data1
58 dbms=csv
59 replace;
60 getnames=no;
61 run;
 
I got this error message:
 
ERROR: Library name is not assigned.
 
Within SAS Studio under Server Files and Folders I have My Folders.  What is probably incorrect above is the first line of code, which specifies "folders/myfolders/test.csv".  Thing is, I don't know how to specify where my little data file is.  Any help appreciated.  Thanks.
 
 
Grand Advisor
Posts: 17,464

Re: After Creating a Library, How do I get a Data Set Into It?

SAS UE is built on a VM so it makes a little diff than dealing with an application installed on your computer. The VM is unix and the path to the shared folders that you created in the setup is correct as specified above.

If you remove test. From your program above you should be able to access your data. Have you tried any of the SAS tutorials? There's a YouTube series and the free SAS programming course.

Or if you switch to process flow method you can use the GUI.
Occasional Contributor
Posts: 6

Re: After Creating a Library, How do I get a Data Set Into It?

"Test" is the name of my data file, so I'm pretty sure I can't remove it and actually access the file, because then my code would not have the name of the file it is tyring to access.

 

I actually figured out a work-around:  1)  Import CSV file into My Folders (easy); 2) Under Output Data select Change button; 3) Save As allows you to save file in Work folder in Libraries with distinct name; 4) Run statistics from table in Work folder.

 

I realize that this will need to be done each time since Work is a temporary folder, but after 5 hours of trying to figure out how to upload a CSV file, it's nice to run some numbers from my data.

 

If anyone has a solution to my original problem, how to actualy get a CSV File into the Library, I'm listening, but for now I'm OK to run my numbers this way.  And again, why does this take more than 30 seconds to figure out?

Solution
2 weeks ago
Grand Advisor
Posts: 17,464

Re: After Creating a Library, How do I get a Data Set Into It?

1. Assign a library - in SAS a library is a directory that you can use to save files. You reference data sets via LIBNAME.DATASETNAME. If you assign the libname by clicking the cabinet icon under Server/Folders you can select an option for the library to stay assigned between sessions of SAS UE. Otherwise you can add the relevant line to your code each time.

 

libname mylib '/folders/myfolders';

2. Import your CSV to SAS dataset.

 

proc import out=mylib.mydata datafile='/folders/myfolders/test.csv' dbms=CSV replace; 
run;

3. Data set is in the library - permanently. If you want to reference it in future programs, assign the libname and go to town.

 

proc print data=mylib.mydata;
run;

4. Your file is ready for analysis in procs

 

proc freq data=mylib.mydata;
table _all_;
run;

proc means data=mylib.mydata;
run;

 

Occasional Contributor
Posts: 15

Re: After Creating a Library, How do I get a Data Set Into It?

If i has old datasets means which were created on sas 9.2,how to use them in sas studio.I assigned a library ------>

libname Data  '/folders/myfolders/'; but i cant see any datasets which were saved in that folder.I'm attaching a screen shot how my datssets look like in a folder..


Screenshot (1).png
Grand Advisor
Posts: 17,464

Re: After Creating a Library, How do I get a Data Set Into It?

Please include screenshots of the Library in SAS Studio

Please show your code and log, including the library assignment and the output from PROC DATASETS 

Occasional Contributor
Posts: 15

Re: After Creating a Library, How do I get a Data Set Into It?

My situation is like this,earlier i used to practice on sas9.2 on windows 32 bit ,as my laptop is not working i moved to other one on which windows 8.1 is installed and it is also a 64 bit platform.I tried to install same sas version i had earlier and failed after that i came to know that there exists some differences between 32 bit and 64 bit.So i moved to sas university version and i copied my datasets on previous computer to folders of sas univ edition via pen drive.so i assigned a library by using libname statment to the same folder where i saved my datsets,but can't see ant datasets inside it.. I'm attching screenshots with a serial number


code i used.pngData saved location.pnglog.png
Grand Advisor
Posts: 17,464

Re: After Creating a Library, How do I get a Data Set Into It?

What happens when you run the following, just paste the log in please, I don't like downloading attachments.

 

libname myData '/folders/myfolders/';

proc datasets lib=myData;
run;

 For example I get:

 

Libref MYDATA
Engine V9
Physical Name /folders/myfolders
Filename /folders/myfolders
Inode Number 5285176
Access Permission rwxr-xr-x
Owner Name UNKNOWN
File Size 3KB
File Size (bytes) 2720
 
# Name Member Type File Size Last Modified
1 CLASS DATA 128KB 2017-05-24 01:58:45
2 CLASS_PERMANENT DATA 128KB 2016-08-20 22:31:13
3 DATEN_EM2012_DUMMIES DATA 128KB 2016-04-21 19:37:04
4 XXXXXXXXXXXXX DATA 19MB 2016-06-10 23:24:25
5 FORMATS CATALOG 24KB 2016-12-29 02:46:21
6 ZZZZZZZZZZZZZZZ DATA 832KB 2016-10-05 04:01:08
7 OUT DATA 128KB 2016-06-16 00:00:35
8 PROSTATECANCER DATA 145KB 2011-01-07 04:25:02
9 SASMACR CATALOG 28KB 2016-09-22 18:51:54
Occasional Contributor
Posts: 15

Re: After Creating a Library, How do I get a Data Set Into It?

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
61
62 proc datasets lib=data;
WARNING: No matching members in directory.
63 run;
 
64
65 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
78
 
Grand Advisor
Posts: 17,464

Re: After Creating a Library, How do I get a Data Set Into It?

Can you upload a dataset?

 

I'm wondering if the 32/64 bit is the issue. I feel like it shouldn't be, but you may have needed to use PROC XPORT/CPORT to transfer the files properly. 

 

 

☑ This topic is SOLVED.

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

Discussion stats
  • 11 replies
  • 3427 views
  • 1 like
  • 4 in conversation