SAS Practice import File

This practice is aiming to help the very beginners to get an idea how to import file without using wizard.

I use SAS Enterprise Guide onDemand for academics, it´s free and you can download it through the official website: http://www.sas.com/en_us/industry/higher-education/on-demand-for-academics.html

Okay, if you want to import file through code, you need either a local server(while it’s not cheap for individual learner), or you need to put the file on SAS Ondemand for Academics Cloud, then run the import code to import your file. While you may wonder why I can import file directly through wizard, however I still make this so complicated to upload to cloud(which pretend I have a server). This article is for practicing import file through code, which you may need later once you have a job in a company, and there will be at least a ftp server, so you can code.

Let’s get start it.

First create a CSV File, save as csv file. and put it in any folder you like.

.create csv

2.  Open data in SAS Enterprise Guide. File- Open – Data

open data.PNG

select csv

And the file displayed should be all comma separated value. Now you need to click save as, it’s at the left corner of the data displaying board. like below picture.

save to sasapp.PNG

 

you can save in any folder of just save it directly in Files.

stored pl.PNG

after you save it, it can be found in Servers panel, expand Servers-SASApp-Files, you will find you file, with an extension of txt, that’s okay since comma delimited file is txt file, or you can just right click the file, rename it as “[your file name].csv”. You can see the file turn to excel icon.

view data location in server

 

We can start coding to import the file to our process now.

click Program-New program, a new tab will pop out, you can program in it.

you can either use code or a procedure. a Procedure is a collection of several statements.

import proc

proc import datafile=”~/WORK/Student_grades.csv”  *location you saved in cloud

out=StudentGrades    *how do you want to name your sasdata in the library

dbms=dlm

replace;
delimiter=’,’;
getnames=yes;
run;

OR you can just simply write an import statement. the highlightings mean

1.how to you want to name your file

2 location of the csv file, delimiter is ‘,'(comma), data row start from 2nd row

3. column names, respectively to the raw data file’s colomns

code to import.PNG

you can run both code to compare. since in this two code, I name the data set differently.

It will look like this, the student_grades two is the import node and STUDENTGRADES is from import procedure.

result.PNG

Thank for reading. Have fun!  If you have any question, please leave your comments down below, I will reply asap.

 

 

 

Leave a comment