Posts

Showing posts from July, 2010

Converting SAS datasets to SPSS

Image
If you want to view SAS dataset in SPSS you can use GET SAS command of SPSS. Here is the syntax; get sas data= 'C:\data\class.sas7bdat' . For conversion of SAS to SPSS we need to see if any formats assigned to variables in the dataset or not. If there are no formats then we just follow following steps to convert SAS dataset to SPSS. **STEP1: Creating .xpt file of a SAS dataset using Proc COPY.** libname SAS 'c:\sas\data\ '; libname SPSS xport 'c:\sas\data\class.xpt' ; proc copy in=sas out =spss; select class; run ; **STEP2: Use SPSS command to convert the transport format SAS file to SPSS;** You should use following commands to convert transport format file to SPSS data. get sas data='c:\sas\data\class.xpt'. execute. *******************************************************************************************; If there are formats then we need to convert the formats catalog to a SAS data set before converting the SAS dataset...

Delete observations from a SAS data set when all or most of variables has missing data

Image
/* Sample data set */ data missing; input n1 n2 n3 n4 n5 n6 n7 n8 c1 $ c2 $ c3 $ c4 $; datalines ; 1 . 1 . 1 . 1 4 a . c . 1 1 . . 2 . . 5 e . g h 1 . 1 . 3 . . 6 . . k i 1 . . . . . . . . . . . 1 . . . . . . . c . . . . . . . . . . . . . . . ; run; *If you want to delete observation  if the data for every variable is missing then use the following code; *Approach 1: Using the coalesce option inside the datastep; data drop_misobs; set missing; if missing(coalesce(of _numeric_)) and missing(coalesce(of _character_)) then delete ; run ;   Pros: *Simple code Cons; *This code doesn't work if we want to delete observation based on specific variables and not all of them. *Approach 2:Using N/NMISS option inside the datastep; data drop_missing; set missing; *Checks the Non missing values using ; if n(n1, n2, n3, n4, n5, n6, n7, n8, c1, c2, c3, c4)=0 then delete ; run; data drop_missing; set missing; *Checks the missing values us...

Diffrence Between RUN and QUIT statements

Folkes,  Here is the answer from Andrew Karp..... Direct link ****************************************************************************************************; Allow me to weigh in on this topic. It comes up alot when I give SAS training classes. First, RUN and QUIT are both " explicit step boundaries " in the SAS Programming Language. PROC and DATA are "implied step boundaries." Example 1: Two explicit step boundaries. DATA NEW; SET OLD: C = A + B; RUN ; PROC PRINT DATA=NEW; RUN ; In this example, both the data and the proc steps are explicitly "ended" by their respective RUN statements. Example 2: No explicit step boundaries. DATA NEW; SET OLD; C = A + B; PROC PRINT DATA=NEW; In this example, the data step is implicitly terminated by the PROC statement. But, there is no step boundary for the PROC PRINT step/task, so it will not terminate unless/until the SAS supervisor "receives" a step boundary. Some PROCS support what is c...