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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

11 REPLIES 11
mohamed_zaki
Barite | Level 11

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.

Sands7
Fluorite | Level 6

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.
 
 
Reeza
Super User
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.
Sands7
Fluorite | Level 6

"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?

Reeza
Super User

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;

 

Bhargav_Movva
Fluorite | Level 6

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
Reeza
Super User

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 

Bhargav_Movva
Fluorite | Level 6

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
Reeza
Super User

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
Bhargav_Movva
Fluorite | Level 6
 
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
 
Reeza
Super User

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. 

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 11 replies
  • 66511 views
  • 8 likes
  • 4 in conversation