Pages

Thursday, March 6, 2014

How to create a PDF file of a SAS job


For creating a PDF file of a SAS job or SAS procedure, we need to bracket the section of code for which you want to create tables or/and graphs:

options orientation=landscape;
ods pdf file=’test.pdf’;
goptions device=pdf colors=(black) rotate=landscape;
...
\SAS\ procedures
...
ods pdf close;

Example:

options orientation=landscape;
ods pdf file=’output-to-Test.pdf’;
goptions device=pdf colors=(black) rotate=landscape;

ods graphics on;

Wednesday, February 26, 2014

SAS Interview questions and answers Part 1

Do you have scheduled interview and want to know about the general questions asked in the SAS interview?
Here are some of the general questions asked in an interview with their answers.


When would you use select instead of IF statement?
A: 
Select is used over IF statement when you are using a condition to compare with several other conditions: Here is an example:

Data exam;
Set exam;
select (pass);
when Physics >60;
when math > 100;
when English = 50;
otherwise fail;
run;

What is the one statement to set the criteria of data that can be coded in any step?


A) Options statement.


What does ERRORS = 1 do in the OPTIONS statement?
A)
If there an error in the data for a observation then ERROR variable will have a value of 1 else 0


Is there any difference between VAR A1 - A4 and VAR A1 -- A4?

A) No, there is no diff between VAR A1-A4 and VAR A1—A4. You can use single (-) or double (--) but if you use more than 2 (---) then it will thrown an error.

Have you seen the error message ""numeric values have been converted to character"? What does it mean?

A) 
It means SAS has automatically converted the numeric variable to character to perform the functions.

Why is a STOP statement needed for the POINT= option on a SET statement?


A) Because POINT= reads only the specified observations, SAS cannot detect an end-of-file condition as it would if the file were being read sequentially.


Can you control the number of observations read in by SAS?
A) Yes, by using FIRSTOBS and OBS option

Approximately what date is represented by the SAS date value of 730?
A) 31st December 1961

Does SAS 'Translate' (compile) or does it 'Interpret'? Explain.
A) Compile

What does the RUN statement do?
A)
SAS editor will start compiling the data or proc step as soon as it encounters the run statement. SO if there are more than one data steps or a proc step followed by a data step then you can avoid using the run statement.

Tuesday, February 25, 2014

How to retrieve the first character of a variable in SAS

If you need to create a variable which has only first character of the character variable, then there are 4 different ways with which you can do the same in SAS. Below each variable B1,B2,B3 and B4 contains Letter A, but the length is not the same for all the four variables.


data test;
 name='Alpha';
 B1 = substr(name,1,1);
 B2 = first(name);
 substr(B3,1,1) = name;
 length B4 $1;
 B4 = name; 
run;

Read data directly from websites in SAS

Do you know you can read data from websites directly? You can use the URL Access Method in the filename statement in SAS.

filename seercode URL "http://www.abc/data.txt";
data siterecode;
infile seercode truncover;
input @1 bigline $char256.;
run;

How to clear library of data in SAS

At times there is a need to clear the permanent library of datasets at one go. There is an option in SAS, PROC DATASETS provides a solution on the proc statement with a Kill Option.

Here is an example:

PROC DATASETS LIBRARY = TEMP KILL;
RUN;

Aliases in SAS

I could choose to let “pp” be 
aliased to “proc print; run;”

Should I want to add a print statement to 
my code, I only need to type: 
pp 
<enter>
and SAS will substitute in the “proc print”
statement.

You can add as many as you want and can 
edit them at a future date

SAS will save these for your next session in 
your SAS profile

These work in Windows, but not sure about 
UNIX OS

Monday, October 14, 2013

Automatic email from SAS after program completion

 If you want to sent an email as soon as your program completes, try:

sas program.sas ; echo program.sas is done | mail youruserid

If you don't want to regularly check the status of the program and wants to get notified to start your next job
If you only want an email if your program bugs out, try:

sas program.sas || echo your program didn't work | mail youruserid

You can write anything that you want in your email after echo.