Posts

Showing posts from 2008

12 Ways to save SAS data

12 Ways to save SAS data source/direct link: http://wiki.binghamton.edu/index.php/12_Ways_to_save_SAS_data 1 Using CARDS; File Save (with editor window active) 1.1 To get it back 2 Cut and Paste (ex. Fixed format data) 2.1 To Get Them Back (space-delimited or fixed-formatted text) 2.2 Links 3 LIBNAME 3.1 To get it (them) back 4 Explorer with one LIBNAME statement?, menu/New Library button, Library Icon 4.1 To get it back 5 DATA ' '; direct access (including Unix ex.) 5.1 To get it back 5.2 Links: 6 In Excel Save As .XLS 7 In Excel Save As CSV (move to Unix, SSH) 7.1 To get it back(in SAS for Windows) 7.2 To Move (Upload) the CSV File from Windows to Unix 7.3 To get the data back (on Unix) 7.4 Links 8 In SPSS Save as 8.1 To get it (our data) back 9 In SAS Save as XPT file 10 XML 11 LIBNAME sasengine 12 DBF (to be written) 12.1 Saving a DBF (from Access?) 12.2 To get it back 13 13 ?PROC DATASOURCE?, ?Stata, ?S-Plus (to be written)

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 ...

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

FIRST. and LAST. variables: Data step processing within by groups using the SET statement

FIRST. and LAST. variables: Data step processing within by groups If you use a by statement along with a set statement in a data step then SAS creates two automatic variables, FIRST.variable and LAST.variable, where variable is the name of the by variable. FIRST.variable has a value 1 for the first observation in the by group and 0 for all other observations in the by group. LAST.variable has a value 1 for the last observation in the by group and 0 for all other observations in the by group. The code shown below is available here . data temp; input group x; cards; 1 23 1 34 1 . 1 45 2 78 2 92 2 45 2 89 2 34 2 76 3 31 4 23 4 12 ; run; /************************************************** The automatic variables first.group and last.group are not saved with the data set. Here we write them to data set variables to show their contents. **************************************************/ data new; set temp; by group; first=first.group; last=last.group; run; proc print; title 'Raw data al...

How to determine the last observation in a data set

Determine the last observation in a data set Use the END= option on a SET statement to determine the last observation of the data set. /* Create sample data */ data company; input division :$12. employees; datalines; sales 150 support 200 research 250 accounting 50 shipping 35 ; run; /* Calculate the total number of employees in each group. */ /* On the last observation of the data set, write out the */ /* resulting total. */ data _null_; set company end=last; file print; /* Sum statement syntax has an implied RETAIN */ total + employees; /* For every iteration of the step, write out the values for */ /* DIVISION and EMPLOYEES. */ put @1 division @15 employees; /* On the last iteration of the step only, write out 4 dashes */ /* starting at column 15, move the internal pointer to the next */ /* line and at column 15 write out the value of TOTAL. */ if last then put @15 '----' / @15 total; run; RESULT: sales 150 support 200 research 250 accounting 50 shipping 35 ---- source: http...

SAS Clinical Interview QUESTIONS and ANSWERS

SAS Clinical Interview Questions and Answers SAS Clinical Interview Questions and Answers Here is a list of common SAS clinical interview questions along with example answers and explanations to help you prepare for your next interview. 1. What is SAS? SAS stands for Statistical Analysis System. It is a software suite used for advanced analytics, business intelligence, data management, and predictive analytics. It is widely used in clinical trials for analyzing clinical data. 2. What are the phases of clinical trials? The phases of clinical trials include: Phase I: Tests safety and dosage with a small group of healthy volunteers. Phase II: Tests efficacy and side effects with a larger group of patients. Phase III: Confirms effectiveness, monitors side effects, and compares with other treatments in larger patient groups. Phase IV: Conducts post-marketing studies to gather additional inf...

How to determine whether a numeric or character value exists within a group of variables

Using the IN operator to determine whether a numeric or character value exists within a group of variables When trying to determine whether a specific value exists within a group of variables, a common approach is to associate the variables with an ARRAY and then use a DO loop to loop through every element or variable in the ARRAY. As an example, here is a segment of code: array my_array[*] var1 - var10; do i = 1 to dim (my_array); if some_value = my_array[ i ] then found = 'Yes' ; end ; A more efficient alternative is to use the IN operator with the name of the ARRAY and avoid using the DO loop. This can be done with both numeric ARRAYS as well as character ARRAYS. Here is a code segment: array my_array[*] var1 - var10; if some_value IN my_array then found = ' Yes '; source: http://support.sas.com/kb/33/227.html

How to convert a SAS date to a character variable

/***************************************************************************//* Title: Convert a SAS date to a character variable *// * *//* Goal: Use the PUT function to create a character variable from *//* a SAS date. *//* *//***************************************************************************/ data one; input sasdate :mmddyy6.; datalines; 010199; run; data two; set one; chardate=put(sasdate,mmddyy6.); run; /* RESULTS */ Obs sasdate chardate 1 14245 010199 Source: ftp://ftp.sas.com/techsup/download/sample/datastep/convertchar.html

How to convert a character variable that represents a date into a SAS date

Convert a character variable that represents a date into a SAS date Use the INPUT function to convert a character value that represents a date into a SAS date value. Data one; input chardate1 :$6. chardate2 :$9. chardate3 $10. chardate4 :$9.; datalines; 010199 31dec1999 21/09/2005 5/9/2005; Run; /* Use the INPUT function to convert a character value that represents a date *//* into a SAS date value. Choose the second parameter to the INPUT function *//* based upon what the current character value looks like. Use a FORMAT *//* statement to apply the date format you want when you are done. *//* *//* Note: If you are in SAS 9.0 or above, you may prefer using the ANYDTDTEw. *//* Informat as the second argument to the INPUT function. ANYDTDTEw. *//* can read multiple date layouts. Refer to the SAS Language Reference, *//* Dictionary under INFORMATS for more information. */ data two; set one; sasdate1=input(chardate1,mmddyy6.); sasdate2=input(chardate2,date9.); sasdate3=input(chardate3,ddmmy...

LAG Function: How to obtain information from previous observation(s)

Often times SAS® programmers need to retain the value of a variable in the current observation to the next observation. The LAG function  can be very helpful here. A LAGn (n=1-100) function returns the value of the nth previous execution of the function. It is easy to assume that the LAGn functions return values of the nth previous observation. Using the LAG function to obtain information from previous observation(s) **********************************************************; /* Sample 1: Create a single lag of one variable */ data one; input x; lagonce= lag (x); datalines ; 1 2 3 4 5 ; proc print data=one; title 'Sample1: Single lag of one variable' ; run ; ***************************************************************; /* Sample 2: Create multiple lags of one variable */ data two; input x; lag1 = lag (x); lag2= lag2 (x); datalines ; 1 2 3 4 5 ; proc print data=two; title 'Sample 2: Multiple lags of one variable' ; run ; ...

IMPLEMENTATION OF CDISC STANDARDS

Image
IMPLEMENTATION OF CDISC STANDARDS Presented By Sandeep Raj Juneja, ASG Inc.... CDISC accomplishments and Strategy CDISC an d Standards for Clinical Research by Rebecca D.Kush, Ph.D, Founder & President,CDISC CDISC SDTM and related initativies CDISC submission standard : CDISC SDTM_Basics Supporting Th e CDISC Standards By Mark Lambrecht,PhD, Principal Consultant,Life Sciences,SAS Case Report Tabulation Data Definition Specification (define.xml) CDISC Study Data Tabulation Model SDTM Implementation Guide V3.1.1 http://www.cdisc.org/models/sdtm/v1.1/index.html Clinical Data Integration: SAS Clinical Data Integration By Dave Smith, SAS UK Industry Standards for the electronic submission of Data to the FDA by Michael A.Walega CDISC SDTM Basics