1 / 18

Some Basics of CQUEST

Some Basics of CQUEST. The operating system in the ESC lab (1046) is Linux. The operating system in RW labs (107/109 and 211) is Windows XP. In all labs, SAS is run from a Linux Server. Your account is the same and files are accessible in all labs. To logout in ESC: look under System

trina
Download Presentation

Some Basics of CQUEST

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SAS lecture - week 3 Some Basics of CQUEST • The operating system in the ESC lab (1046) is Linux. The operating system in RW labs (107/109 and 211) is Windows XP. In all labs, SAS is run from a Linux Server. Your account is the same and files are accessible in all labs. • To logout in ESC: look under System • To logout in RW: look under Start • In ESC, if you want a terminal window you can either right click on the desktop or click on Applications and then Accessories. • In RW, if the backspace doesn’t work in SAS, turn off Num Lock.

  2. SAS lecture - week 3 Using SAS: Batch vs Window Mode • In both ESC and RW labs SAS run in a Windows mode. • In a window mode you can have access to SAS help and have a better control of graphics. • On the other hand, SAS help isn’t great and to be able to use Window mode you either need to purchase site license or be in CQUEST lab. • If you wish to use SAS on CQUEST from home you will need to use batch mode which require learning some Unix commands.

  3. SAS lecture - week 3 Starting SAS Window Mode • In ESC, under Applications choose CQUEST and then SAS or type sas at a comand prompt in a terminal window. • In RW, under Start choose Statistics Apps and then SAS. • You will have to enter your CQUEST password. • Many windows will open including: • a program editor where you type your SAS program. • a log window ( .log file) • an output window ( .lst file) • An explorer for navigating through your windows and output • a graphic window will open once you have run a program that produces graphic plots

  4. SAS lecture - week 3 How to Run a Program • There are two ways to run a program in SAS… • You can type your code in the program editor window, make this window your primary window (click on it) and then click on the running man. The code will disappear. To get it back under Run select Recall last submit. • Alternatively, you can write your SAS program in a text file and save it in your home directory. In the explorer window (in SAS) find the file under the directory you save it and double click on it. A new window with your text file will open. You can then highlight the code you wish to run and past it into the program editor window. • Running a program writes output to a log window, an output window (if the program ran without errors) and sometimes graphic window. • The SAS log window (or .log file) contain messages from SAS about your program written when you run it. Always check it for Errors.

  5. SAS lecture - week 3 Batch Mode • Batch mode is useful when working at home by using ssh to access CQUEST at login.cquest.utoronto.ca. • To use batch mode in a lab you need to open a terminal window. • Using batch mode require to know some Unix. • There is no access to SAS help files when using batch mode.

  6. SAS lecture - week 3 Running SAS Programs in Batch Mode • Store your program in a text file called filename.sas and at a command prompt type sas filename. • This creates filename.log and, if there were no errors in your program, filename.lst. • If your data are in a separate file, you need to first save the data in a text file on your CQUEST account under the same directory where your program is stored. • In ESC, graphics will pop up in a new window on the screen. To save or print graphic plots, see the SAS code on slide 14. • Note also, that to print files on CQUEST at home you will have to first ftp them to your home computer. • If any of your SAS batch jobs have a problem and keep running, you must kill them. Type ps at a prompt tp get the number of the SAS job (the PID), and then type kill -9 thePIDnumber to kill a job.

  7. SAS lecture - week 3 Basic of SAS Programming • Every line ends with a semi-colon (;). • SAS is not case sensitive; HadaS and hadas are the same withing a program. • Anything between /* and */ is a comment. • A typical SAS program has data steps (to create and manage your database) and procedures starting with the reserved word proc. • The last line of the program should be run;. • You can add titles to your output with the command title ‘This is my title’; at the beginning of your program or within any procedure. • SAS has crazy ideas about line lengths. To fix this make options linesize = 79; the first line of your program. (There are many other options you can set, but this is the only one that is essential.) • Every line ends with semi colon.

  8. SAS lecture - week 3 The Data Step • The code below create a dataset called snow. • The data are read from the file gauge.txt. • The data file is just a text file, with a new line for each observation. • Because the first line of the data file contains the names of the variables and not data, we need to specify firstobs=2. data snow; infile ‘gauge.txt’ firstobs=2 ; input density gain; loggain=log(gain); run; • If using MSWindows version of SAS at home, you will need to specify the entire file path to the data in your SAS program.

  9. SAS lecture - week 3 More on the Data Step • The code below creates a new dataset which starts with the data set snow but only includes observations for which the density is less than 0.6. data lesssnow; set snow; if density <0.6; • To download a data file from the web onto your CQUEST account, right click and save (under This Frame if the data are within a frame). • For more instructions on constructing and manipulating SAS datasets see the hand-out posted on the course webpage.

  10. SAS lecture - week 3 Some SAS Procedures • By default any procedure operates on the last dataset you created. To change this, add data = dataset_name on any proc line before the semi colon. • Proc gplot - Graphic plots go into a graphic window (from which they can be printed or saved individually). For a variable1 versus variable2 scatterplot : Proc gplot; plot variable1*variable2; • Proc print; print the contents of the last dataset; • Proc corr; prints summary statistics and pairwise correlations for all quantitative variables.

  11. SAS lecture - week 3 • Proc univariate plot; var variable_name; Gives many summary statistics and basic plots (or no plots if you leave out the word plot). If you add the word normal SAS will do a few normality tests. • The minimum commands for regression where variable1 is the independent variable and variable2 is the dependent variable: Proc reg; model variable2= variable1; • Proc glm can also be used for regression but has fewer options.

  12. SAS lecture - week 3 More on Proc Reg • There are many more commands you can add to all procedures, but we will focus on proc reg. More will arise in class as needed but here are some commonly used plotting commands: proc reg simple; model y=x; plot y*x; /*scatterplot with fitted line*/ plot r.*x; /*plot of residuals vs x */ plot r.*p; /*plot residuals vs predicted */ • The keyword simple gives basic summary statistic for y and x. • Note that the plots produce within proc reg are graphics plots. To produce non-graphics plots; add the keyword lineprinter on the proc reg line. Variable names that end in a period are variables created by SAS.

  13. SAS lecture - week 3 Saving Residuals and Predicted Values • Saving residuals and predicted values to a dataset is useful if you want to do more analysis on the residuals or plot them. • The following code creates a new dataset called outdata that includes all the variables in the original dataset plus variables called pred (the predicted values) and resid (the residuals). Proc reg; model variable2=variable1; output out=outdata p=pred r=resid;

  14. SAS lecture - week 3 Saving Graphics Plots to a File • In SAS window mode, make the graphic window your primary window, choose File from the toolbar and then to print select Print or to save select Export as Image. • If you are working at home by using ssh to access CQUEST you will want to save graphic plots in files within the SAS program so that you can sftp them to your home computer or print them when you come to campus. • The following commands save graphics plots in gif format to files in your home directory. filename grafout ‘.’; goptions device=gif gsfname=grafout; • The file are named by the SAS procedure that created them. For example, if you have requested 3 plots within proc reg the plots will be stored in the files reg.gif, reg1.gif, and reg2.gif. • Instead of gif you can specify jpeg and other image formats.

  15. SAS lecture - week 3 Example – Smoking and Cancer Option ls=79; /* Data within program rather than in separate file*/ Data smoking; Input occupational_group $ smoking mortality; Datalines; Farmers_foresters_fisherman 77 84 Miners_quarrymen 137 116 Gas_coke_chemical_makers 117 123 Glass_ceramics_makers 94 128 ; Proc corr data = smoking; /*Change plotting symbol to a black dot*/ Symbol1 v=‘dot’;

  16. SAS lecture - week 3 Proc gplot; plot mortality*smoking; Proc reg data = smoking; model mortality = smoking; plot mortality*smoking; plot r.*smoking; plot r.*p. Run; • Note that there are no semi-colon after each of the data lines, but just one at the end. • To save space for this example, I have left out most of the data. The full dataset is on the course website. • Also, note that since occupational_group is character data there is a $ after its name in the input statement.

  17. SAS lecture - week 3 A Few Unix Commands • These can be executed from a terminal window in ESC or from home when accessing CQUEST through ssh. • exit – Logs you off. • Passwd – Change your password. • Man command – Unix help for command • ls – List the files in the current directory. • mkdir directory_name – Make a new directory. • cd directory_name – Changes directory to directory_name. • cd – Changes to your home directory. • less file_name – Display the content of file_name on your screen (q to quit). • rm file_name – remove file_name. • cp file_name1 file_name2 – Copies file_name1 to file_name2. • mv file_name1 file_name2 – Moves (rename) file_name1 to file_name2.

  18. SAS lecture - week 3 • Editors: in ESC lab, try gedit filename (the default editor). filename can be a new file. • Gedit is available as Text Editor when you right-click on an existing file. • If you are using ssh, try vi filename but first learn a bit about vi. If you google “vi unix editor’ you will find some good tutorials.

More Related