Toronto STA 302 H1F - Introduction to SAS for Regression

Unformatted text preview:

STA 302 / 1001Introduction to SAS for Regression(on CQUEST)A.L. GibbsSeptember 2011Some Basics of CQUESTIThe operating system in the RW labs (107/109 and 211) isWindows XP. There are a few terminals in RW 213 runningLinux. SAS is run from a Linux server. Your account is thesame and files are accessible in all labs / operating systems.ITo logout:IWindows: look under StartILinux: look under SystemITo open a web browser:IWindows: Firefox is an icon on your desktop.ILinux: Firefox is the mouse on a globe icon on the toolbar.IIf backspace doesn’t work in SAS, turn off Num Lock.IUse the Insert key to toggle between insert and type-overmodes.ILinux: If you want a terminal window you can either right clickon the desktop or click on Applications and then Accessories.Accessing CQUEST RemotelyIMac: Use an X11 terminal window. Command:ssh -X -l cquestuserid login.cquest.utoronto.caIWindows: need PuTTY and Xming (free downloads). See thecourse announcements on Blackboard for a link to completeinstructions to set this up.IAll files will be on CQUEST and not on the computer you’reworking on. So the data file needs to be saved on yourCQUEST account and SAS output will be on CQUEST. Usean sftp program to transfer files. For example, to print SASoutput at home you’ll need to transfer the files to your homecomputer. (I recommend the sftp programs WinSCP for MSWindows and Fugu for Mac OS X; both can be downloadedfor free.)Using SAS:Batch Mode vs the SAS Windowing EnvironmentIThe SAS Windowing Environment on CQUEST (Linux) issimilar to the version of SAS I’ll demonstrate in lecture (MSWindows).IAlternatively you can use batch mode, creating your SASprogram using the editor of your choice and running it at acommand prompt.IWhen accessing CQUEST remotely, the SAS WindowingEnvironment can be very slow so you may want to try batchmode.A Picture of the SAS Windowing Environment onCQUESTStarting the SAS Windowing EnvironmentIMS Windows in a CQUEST lab: Under Start choose StatisticsApps and then SAS.ILinux machine in RW 211: Under Applications chooseCQUEST and then SAS or type sas at a command prompt ina terminal window.IWhen accessing CQUEST remotely: type sas at a commandprompt.IYou will have to enter your CQUEST password.IDouble-clicking on a previously saved SAS program doesn’twork. To open a previously saved program, open SAS andthen choose File > Open.Starting the SAS Windowing Environment continuedMany windows will open including:Ia program editor where you type your SAS programIa log windowIan output windowIan explorer for navigating through your windows and outputIa graphics window will open once you’ve run a program thatproduces graphics plots (except if the plots are produced usingthe Output Delivery System (ODS))IMPORTANT FIRST STEPThe version of SAS on CQUEST is 9.3. By default, this version ofSAS uses ODS to save all graphs in graphics files (png) and outputin an html file sashtml.htm. TURN THIS OFF. To do this:Tools > Options > Preferences...IMPORTANT FIRST STEP continuedSelect: Create ListingSAS Help on CQUESTThe SAS help is not completely installed on CQUEST. You mayaccidentally end up with this dialogue box.If you do, everything will stop until you click OK.More on the SAS Windowing EnviromentITo insert a line after the current line in the SAS programeditor, type an i in the leftmost column over the first zeroand hit enter. (For more tricks you can use in the SASprogram editor, google “SAS Text Editor Line Commands”.)ITo run a program: Make the program editor window yourprimary window (click on it) and click on the running man orselect Run and then Submit. Running a program writesoutput to a log window, an output window (if the programran without errors) and sometimes a graphics window. Yourcode will also disappear. To get it back under Run selectRecall last submit.INote that you need to save your program, your output, andyour graphics files separately if you want to keep them.Using SAS in Batch ModeIStore your program in a (text) file calledfilename.sas and at a command prompt type sasfilename. This creates filename.log and, if your run wassuccessful, filename.lst.IIf you are using batch mode in an Xwindows terminal (MacX11 or Xming), graphics will pop up in a new window on thescreen. To save graphics plots (and then print them), there issome SAS code in a later slide (or use ODS).IIf any of your SAS batch jobs have a problem and keeprunning, you must kill them. Type ps at a prompt to get thenumber of the SAS job (the PID), and then type kill -9thePIDnumber to kill a job.SAS Log Window (or .log file)Messages from SAS about your program written when you run it.Always check for ERRORs.Basics of SAS ProgrammingIEvery line ends with a semi-colon.ISAS is not case sensitive; GIbbS and gibbs are the samewithin a program.IEvery line ends with a semi-colon.IAnything between /* and */ is a comment.IYou can also comment out a single line by starting with a *but then it must end with a semi-colon.IA typical SAS program has data steps (to create and manageyour datasets) and procedures starting with the reserved wordproc.More Basics of SAS ProgrammingIUse run; after every procedure.IYou can add titles to your output with the commandtitle ‘This is my title’;at the beginning of your program or within any procedure.ISAS has crazy ideas about line lengths. To fix this makeoptions linesize=79;the first line of your program. (There are many other optionsyou can set, but this is the only one that is essential.)IEvery line ends with a semi-colon.The Data StepThe code below creates a dataset called to1993.data to1993;infile ‘maunaloadata.txt’ firstobs=33;input year 1-4 month 6-7 day 9-10 time1 $ date $time2 $ cfc11 nd sd f cs rem;if cfc11 < -9999 then cfc11=.;time=year+(month-1)/12;drop day time1 date time2 nd sd f cs rem;IThe data are read from the file maunaloadata.txt.IThe data file is a text file, with a new line for eachobservation.IBecause the first 33 lines of this file contains information andnot data, we need to specify firstobs=33.IBecause the dates are in the form 1993-01-01, we specifiedthe columns of the data file that contain the year, month, andday.The Data Step continuedIThe rest of the variables in the datafile are delimited byspaces. (If they were delimited by commas, you would adddlm=‘,’ to the infile line.)IA $ after a variable name on the input line indicates thatthe variable is character (rather than numeric) data. (I didthat here since the times and dates


View Full Document

Toronto STA 302 H1F - Introduction to SAS for Regression

Download Introduction to SAS for Regression
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to SAS for Regression and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to SAS for Regression 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?