Wednesday, November 19, 2008

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 questionable step, the variable characteristics will be appropriate; after the step they will be inappropriate.

4. Look carefully at the code for that step. Continue using PROC PRINT, PROC FREQ, and PROC MEANS to examine the effect of each statement. In this way, you can identify the exact statement or statement group that is not working as you expect.

5. Next, get a clear understanding of how the statement is working (as opposed to how you think it should work) by consulting the SAS Help function; click on the Help button in the SAS menu bar and scroll to SAS Help and Documentation; then, search for the particular statement or procedure. The results in hand should help you interpret the documentation.

6. Finally, determine the appropriate code for your needs. Remember to check for other statements that involve this mistake.

5 comments:

Anonymous said...

hi there, i've a dataset with 1000 observations.
each observation will have patience id and other variables.
I need to find out how many patience ids have missing variables in the following layout.

patience id missing variable name
100 age
101 age,height
so i need help to get this kind of output.

sarath said...

data dsn;
input patid $ age height;
datalines;
100 25 150
101 27 152
102 26 .
103 . 167
104 . .
105 23 169
;
run;

data new;
set dsn;
if age eq . or height eq .;
keep patid;
run;


output:

patid
102
103
104

Anonymous said...

Use above dataset dsn and do as below:

DATA MAGE(KEEP = PATID MISS1) MHEIGHT(KEEP = PATID MISS2);
SET dsn;
IF AGE = . THEN DO;
MISS1 = 'AGE';
OUTPUT MAGE;
END;
IF HEIGHT = . THEN DO;
MISS2 = 'HEIGHT';
OUTPUT MHEIGHT;
END;
RUN;
PROC SQL;
SELECT Coalesce(A.PATID, B.PATID) AS PATID, A.MISS1, B.MISS2 FROM MAGE AS A FULL JOIN MHEIGHT AS B ON A.PATID = B.PATID;
QUIT;


OUTPUT :

PATID MISS1 MISS2
102 HEIGHT
103 AGE
104 AGE HEIGHT
.
.
.


HOPE THIS HELPS!

IF ANY ISSUE CONTACT net_ameen@rediffmail.com

Anonymous said...

how to create apermanent data set

Post a Comment

ShareThis