Discover More Tips and Techniques on This Blog

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 option which means "full screen device". You could add another SAS system option to this command, such as the -work option mentioned above:
/usr/local/sas/sas -fsd ascii.vt100 -work ./mysasdir

If you run SAS noninteractively by supplying the SAS program file "mysasprog" in the current directory, you would change your command from:
/usr/local/sas/sas mysasprog
to:
/usr/local/sas/sas -work ./mysasdir mysasprog

This would direct SAS to write any work files to the "mysasdir" directory as it processes the contents of your SAS program "mysasprog".

Each of these examples assumes you want to use a particular SAS system option once or a few times. If you intend to use a SAS system option repeatedly, it can be a nuisance to specify the same option each time you invoke SAS. For this type of situation, you can copy the config.sas612 file located in the /usr/local/sas/sas612 directory and edit it using a UNIX text editor.

The config.sas file is a SAS configuration file that contains default settings for a number of SAS system options; you may change the default settings of these options as well as delete or add options of your choosing to this file. If you then launch SAS from the same directory as the config.sas612 file, SAS will use those options.

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.

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 macro file (and the name of the macro in the %MACRO statement).
For example if you had a macro to do a PROC PRINT stored in a file called "prt.sas", it could look like this:

%MACRO prt;
PROC PRINT;
RUN;

%MEND;

If you stored this file in your $HOME directory, you could run the SAS job:

FILENAME wheremac '$HOME/';
DATA one;
INPUT a b ;
CARDS;
1 23 2;
OPTIONS SASAUTOS=wheremac;
%prt
The above code will create the data set and print the data to the SAS listing file.

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.