Write and run SAS programs in your web browser

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

Reply
Occasional Contributor
Posts: 6

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.

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: 16,378

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?

Grand Advisor
Posts: 16,378

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;

 

Post a Question
Discussion Stats
  • 5 replies
  • 2062 views
  • 0 likes
  • 3 in conversation