Discover More Tips and Techniques on This Blog

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:

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

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

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

    ReplyDelete
  4. how to create apermanent data set

    ReplyDelete
  5. You can check data Syntax function code.

    ReplyDelete

Disclosure:

In the spirit of transparency and innovation, I want to share that some of the content on this blog is generated with the assistance of ChatGPT, an AI language model developed by OpenAI. While I use this tool to help brainstorm ideas and draft content, every post is carefully reviewed, edited, and personalized by me to ensure it aligns with my voice, values, and the needs of my readers. My goal is to provide you with accurate, valuable, and engaging content, and I believe that using AI as a creative aid helps achieve that. If you have any questions or feedback about this approach, feel free to reach out. Your trust and satisfaction are my top priorities.