Posts

Getting the Data into SAS

GETTING DATA INTO SAS direct link: http://www.biostat.ucla.edu/course/m403b/M403B2005_2DataInput.pdf 1. Importing data from other sources • Use DBMS Copy, STAT Transfer, or some other software that performs similar functions. • Use SAS/ACCESS or the SAS Import feature in Windows. • Use PROC IMPORTS to read certain types of data files. • Create a raw data (ASCII) file then use INPUT and INFILE statements to read the raw data file in SAS programs. 2. Creating SAS data sets with raw (ASCII) data files • Data are placed within the SAS program directly after the DATALINES or CARDS statement. Use INPUT statement to read the data. *** Read data within SAS program as SAS data file ***; DATA survey; INPUT Q1Major Q2Degree Q3SASpast Q4ProjData Q5SASexprn Q6SASfutur; DATALINES; 2 1 1 1 2 8 2 2 0 0 0 7 2 1 0 0 1 4 2 1 0 1 0 8 more raw data lines ; RUN ; • In the above example, – Spaces (or other types of delimiters) are required between data values – Missing values must be specified (blank sp...

How to detect missing values using ARRAYS

Using an array in SAS to detect missing values Direct link: http://ssc.utexas.edu/consulting/answers/sas/sas65.html Question: How do I exclude observations from my PROC FREQ analysis when a value is missing from a list of variables? Answer: In the SAS DATA step, you can create a new variable ("miss" in the example below) that is set equal to 1 when a variable has a missing value, 0 otherwise. Use the ARRAY statement and a DO loop to check for missing values across a list of variables; the syntax is: DATA one ; INFILE xxx; INPUT a b c d e; miss= 0 ; ARRAY vv(5) a b c d e ; DO i= 1 TO 5 ; IF vv(i)=. THEN DO ; miss=1 ; i=5; END; END; RUN; PROC FREQ; WHERE miss =0; TABLES a b c d e ; RUN ; Here, the array "vv" has 5 elements (a,b,c,d,e), and the loop "i" is likewise set to 5. For each observation, the loop iterates 5 times, checking for missing values across the list of 5 variables. When a missing value ...

SAS System Options in the UNIX environment

SAS System Options in the UNIX environment Direct link: http://ssc.utexas.edu/consulting/answers/sas/sas55.html Question: How do I specify SAS system options in the UNIX environment? Answer: How you specify SAS system options depends on how you use SAS in the UNIX environment. If you use SAS via an X-terminal or X-terminal emulation software such as Exodus or MacX, the command to launch SAS on ITS UNIX systems is /usr/local/sas/sas SAS system options are preceded by a hyphen and immediately follow the SAS command. For example, if you want to have SAS write its work files (including temporary datasets) to a directory called "mysasdir" located one level below your own current working directory, the syntax for invoking this option would be: /usr/local/sas/sas -work ./mysasdir If you use the SAS display manager system via a vt100 terminal interface such as telnet, the usual command to launch SAS is: /usr/local/sas/sas -fsd ascii.vt100 The -fsd portion of this command is a SAS opt...

How to Debug the SAS code

Debugging SAS code Direct link: http://ssc.utexas.edu/consulting/answers/sas/sas54.html Question: I have a huge SAS program that isn't working. The results I get are not right but there are no errors or warnings in the SAS log. How can I figure out where I went wrong? Answer: To debug a SAS program that produces no syntax errors, follow these six steps: 1. Check to see that your original data input is correct for all variables. 2. If the data is input to SAS correctly, go to the other end of the program. Select a variable or a small set of variables involved in the analyses where you get the wrong results. Use PROC FREQ, PROC MEANS, and/or PROC PRINT to examine these variables. There should be a problem with at least one; identify exactly how these variables are incorrect. 3. Now follow these variables back through each operation you performed, always looking at the characteristics in question. In this way you can narrow down the exact step where an error occurs. Prior to the qu...

How to call SAS macros on UNIX

SAS FAQ #64: Calling SAS macros on UNIX systems source: http://ssc.utexas.edu/consulting/answers/sas/sas64.html Question: On UNIX how do I call an external SAS MACRO that is in another file and not physically included in my SAS program? Answer: Put the SAS MACRO in a file having a name "macro_name.sas", where "macro_name" is the macro name from the SAS %MACRO statement. When you want to use this macro in a SAS program, perform the following steps: 1) Use a FILENAME statement of the form: FILENAME wheremac ' dir '; where "wheremac" is a fileref pointing to the directory where the macro file is stored, and "dir" is the directory path to where the macro file is stored. 2) Use an OPTIONS statement of the form: OPTIONS SASAUTOS=wheremac; to point to the directory containing the macro file. 3) Use a call for your macro as you normally would with the "%macroname" specification, where "macroname" is the first name of the mac...

SAS Certification Assignments

SAS Certification Assignments Contents[ hide ] 1 Session 1 1.1 exercise 1 1.2 exercise 2 1.3 exercise 3 1.4 exercise 4 1.5 exercise 5 1.6 exercise 6 2 Session 2 2.1 exercise 1 2.2 exercise 2 2.3 exercise 3 2.4 exercise 4 2.5 exercise 5 3 Session 3 3.1 Exercise 1 3.2 Exercise 2 3.3 Exercise 3 3.4 Exercise 4 4 Session 4 4.1 Exercise 1 4.2 Exercise 2 4.3 Exercise 3 5 Session 5 5.1 exercise 1 5.2 exercise 2 5.3 exercise 3 5.4 exercise 4 5.5 exercise 5 6 Session 6 7 Session 7 7.1 exercise 1 7.2 exercise 2 7.3 exercise 3 8 Session 8 8.1 exercise 1 9 Session 9 9.1 exercise 1 SAS Certification Examples(part 2) Session 6 1.1 Example 1 1.2 Example 2 1.3 Example 3 1.4 Example 4 1.5 Example 4a 1.6 Example 5 1.7 Closing examples 2 Session 7 2.1 In class 2.2 Some similar functions,formats and informats 3 Session 8 4 Session 9 4.1 Example 1 4.2 Example 2 4.3 Example 3 4.4 Example 3A 4.5 Exa...

INDEX TO SAS TUTORIALS

Index to Statistics Tutorials PROC MEANS Tutorial (Descriptive statistics) PROC UNIVARIATE Tutorial (Distribution analysis) New: PROC UNIVARIATE - Advanced Tutorial PROC CORR Tutorial (Correlation) PROC FREQ Tutorial 1 (Frequency Tables/Goodness of Fit) PROC FREQ Tutorial 2 (Two-way tables) PROC TTEST Tutorial (Two sample and paired t-tests) New: A comparison of Paired & Independent Sample t-test s PROC ANOVA & GLM Tutorial (One-Way ANOVA) PROC GLM Tutorial (Repeated measures ANOVA using PROC GLM) New: Survival Analysis & comparison of groups using PROC LIFEREG Bland-Altman Analysis (Comparing two measures) Inter-Rater Reliability, Kappa, Weighted Kappa (PROC FREQ) New: SAS Functions (2-part tutorial) Special SAS Topics New: Read and Write SAS Data Sets the EASY way Setting the SAS Initial Folder (default directory) Using SAS ODS Output, Styles, Graphics, Data Data files and SAS code for tutorials