Monday, April 2, 2018

My Top 21 SAS Interview Questions

SAS Programming Professionals,

With over 32 years of SAS programming experience, I have certainly faced a lot of SAS interview questions; as both interviewee and interviewer.  Perhaps that is why I love the spate of occasional postings purporting to show the Top X SAS Interview Questions.  I can never figure out just how the authors decided upon the exact number (X) of top interview questions.  Nor, can I determine whether most of those authors have any substantial grasp of SAS programming knowledge or whether they are simply creating click-bait for some product or service.  But, the Top X SAS Interview Questions posts are so funny that I never fail to read them.

Here is my own list of the Top 21 SAS Interview Questions:


1.      What does SAS stand for?

In the United States, SAS stands for the national anthem.

2.      What is more powerful, the DROP statement or the KEEP statement?

The DROP statement is more powerful because it has gravity on its side.

3.      How do you run a RUN statement?

In SAS Display Manager, you run the RUN statement by clicking on the RUN icon.

4.      Which do economists use more, the IMPORT or the EXPORT procedure?

In the United States, there are far more IMPORTs than EXPORTs.

5.      What is PROC THIRTEEN and how do you use it?

This is a trick question.  PROC THIRTEEN, the bad luck proc, sometimes known as “the black cat proc” or “the cracked mirror proc” is a mythical procedure that has never really been offered to SAS users.  It is purportedly designed to generate random inauspicious numbers for its users.  Though there are many rumors about the existence of PROC THIRTEEN, it cannot be found in SAS documentation, nor does it appear to be an undocumented feature of Base SAS.

6.      What is the advantage of sorted SAS data sets?

Sorted SAS data sets are already sorted so you do not have to sort them.

7.      Why is PROC CONTENTS sometimes referred to as the “411 procedure?”

PROC CONTENTS is sometimes called the “411 procedure” because it gives you all of the information you need about the files in a SAS directory.

8.      What is the result of running the following program:

data _null_;
input x $;
x=reverse(x);
put x;
datalines;
SAS
;;;;
run;

The result is: “SAS”.

9.      What SAS procedure rhymes with doormat?

FORMAT.

10.   Name the two geological DO statements and explain the reason for their nicknames.

The “DO WHILE” statement is known as the “Stalactite DO” since it is evaluated at the top.  The “DO UNTIL” statement is known as the “Stalagmite DO” since it is evaluated at the bottom.

11.   True or false:  You need apply for a Federal Explosive License (FEL) from the US Bureau of Alcohol, Tobacco, Firearms and Explosives, and receive special training to use PROC EXPLODE in your SAS programs?

False.

12.   Is it better to have one big SAS data set or many smaller SAS data sets?

It is much better to have many smaller SAS data sets because that makes it look like you have done more programming work.

13.   Which of the following is not a regular expression:
a.      I’ll be right back.
b.      Hold my beer and watch this.
c.       re = prxparse('/[bc]d(ef*g)+h[ij]k$/');x
d.      A day late and a dollar short.
e.      Fname = substr(fullname, 1,15);

The answer is E.

14.   Which SAS procedure best completes the following sentence:  The tugboat helped the container ship navigate its way into the _______.

CPORT.

15.   What is the most common use for the SUBSTR function?

The overwhelming majority of SAS programmers that use the SUBSTR function use it to extract a substring from an argument.

16.   Under what circumstances can you code a RUN statement before a DATA statement?

A RUN statement can be coded before a DATA statement when the RUN statement belongs to a previous DATA step or PROC step.

17.   Which of the following is a valid type of SAS merge:
a.      Heaps to tons
b.      Countless to oodles
c.       Several to some
d.      One to many
e.      Numerous to a handful

The answer is D.

18.   Who is the Co-Founder and Chief Executive Officer of the SAS Institute?
a.      Jonny Goodtimes
b.      Jakob Gutenacht
c.       Dr. James Goodnight
d.      Benito Androssi
e.      Jamie Goldenboy

The answer is C.

19.   Which of the following prepositions occurs as a valid statement in the most SAS procedures:
a.      UNDERNEATH
b.      THROUGH
c.       BEYOND
d.      BETWEEN
e.      BY

The answer is E.

20.   Is the following statement true or false:  If you code five or more of the same variables on both a DROP and a KEEP statement in a DATA step, your program will catch on fire upon execution.

The statement is:  False

21.   Is the following statement true or false:  You should be very wary of lists posted on social media that purport to show the top SAS interview questions.

The statement is: True


Best of luck in all your SAS endeavors!


---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

Monday, March 26, 2018

Hack 7.8 Getting The Process ID (PID) On UNIX and Linux




SAS Programming Professionals,

Did you know that you can use &SYSJOBID to get the Process ID (PID) of SAS tasks running on UNIX and Linux servers? 

This can be useful for differentiating between multiple SAS sessions you have running on a UNIX or Linux server.  It is also useful when you want to correlate the PID of a particular SAS batch task with UNIX or Linux system performance information. 

Here is an example of using &SYSJOBID that I have coded in many of my SAS/Connect programs:

data _null_;

pid     = &SYSJOBID;

put '******************************************************';
put '*                                                    *';
put '*The Process ID of this SAS/Linux Session is: ' pid '*';
put '*                                                    *';
put '******************************************************';

run;

This code produced the following in the SAS log when running from a PC client to a Linux server:

******************************************************
*                                                    *
* The Process ID of this SAS/Linux Session is: 31037 *
*                                                    *
******************************************************

It might make sense to use &SYSJOBID to document the PID of all of your SAS programs running in UNIX environments.  That way; you will always have that information in your SAS log if you ever need it. 

Best of luck in all your SAS endeavors!

---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers

Monday, March 19, 2018

Hack 7.7 Dynamically Concatenating SAS Libraries




SAS Programming Professionals,

Did you know that you can dynamically insert and append SAS format libraries and macro libraries to your list of available SAS libraries dynamically within a SAS program? 

The INSERT= SAS option allows you to insert a libref as the FIRST in a series of librefs that SAS will search.  The APPEND= SAS option allows you to append a libref as the LAST in a series of librefs that SAS will search.  These two options work to modify the following SAS system options’ settings:

·        CMPLIB=
·        FMTSEARCH=
·        MAPS=
·        SASAUTOS=
·        SASSCRIPT=

Here is an example of using the INSERT= option:

libname templib "c:\temp";

options insert=(fmtsearch=(templib));

… after the code, above, has run, PROC OPTIONS will reveal that the TEMPLIB format library is placed ahead of the other SAS format libraries that SAS searches for a particular format:

FMTSEARCH=(TEMPLIB WORK LIBRARY)

Conversely, in this example of the APPEND= option:

libname templib "c:\temp";

options append=(fmtsearch=(templib));

… after the code, above, has run, PROC OPTIONS will reveal that the TEMPLIB format library is placed after the other SAS format libraries that SAS searches for a particular format:

FMTSEARCH=(WORK LIBRARY TEMPLIB)

Prior to the implementation of the INSERT= and APPEND= options, you either had to modify the –INSERT and –APPEND options in your SAS CONFIG file (and then launch SAS), or you had to specify the search order of _ALL_ libraries via the FMTSEARCH=, SASAUTOS=, etc. options within a program.  Now, you can pre-append or append the various format, macro, etc. libraries for your various projects or users on the fly.  This is a BIG step forward thanks to the brainiacs at the SAS Institute! 

In summary, you can use:

·        INSERT= to pre-append libraries so they will be searched FIRST in the search pattern when specifying CMPLIB=, FMTSEARCH=, MAPS=, SASAUTOS=, and SASSCRIPT= option statements.

·        APPEND= to append libraries so they will be searched LAST in the search pattern when specifying CMPLIB=, FMTSEARCH=, MAPS=, SASAUTOS=, and SASSCRIPT= option statements.

Pretty nifty, eh?

Best of luck in all your SAS endeavors!

---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers

Monday, February 12, 2018

Michael A. Raithel's SAS Limerick #4

SAS Programming Professionals,


Something to make you smile while you write programs today:

    I once inherited a SAS macro so intense,

    That its logic just did not make sense,

    I thought that MLOGIC, SYMBOLGEN, and MPRINT,

    Would show me where the macro's logic ultimately went,

    But the resulting log was too overly dense.

Best of luck in all your SAS endeavors!


---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

Hack 7.6 Determining SAS Files Types by Their Extensions




SAS Programming Professionals,

Did you know that you can quickly determine the nature of SAS files when viewing them on your operating system via their file extension? 

Knowing what SAS file type corresponds to the file extension can be handy when combing through directories in Windows Explorer or in native Linux.  Here are the file extensions:

Easy:

·        .sas      - SAS program
·        .log      - SAS log
·        .lst      - SAS list
·        .sas7bdat - SAS data set

More Obscure:

·        .sas7bndx - SAS index
·        .sas7bcat - SAS catalog
·        .sas7bvew - SAS view

Most Obscure:

·        .sas7bmdb - SAS MDDB
·        .sas7bitm - SAS Itemstore

You can get a list of SAS file extensions for you particular environment by accessing the SAS online documentation and viewing the SAS Companion document for that operating system.  For example, if you were using Windows, you would access the SAS 9.4 Companion for Windows and search for “file extension”.  That will net you a web page with a very nice table of SAS file extensions.  Check it out!

Best of luck in all your SAS endeavors!

---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers

Monday, February 5, 2018

Michael A. Raithel's SAS Limerick #3

SAS Programming Professionals,


Something to make you smile while you write programs today:

    In my SAS logs nothing could be rarer,

    Than to find a SAS WARNING or ERROR,

    Because I buy books from SAS Press,

    To keep my syntax from being a mess,
   
    Every one of my logs is a good news bearer.


Best of luck in all your SAS endeavors!


---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

Hack 7.5 Creating SAS Data Sets with Another Operating System’s Data Representation




SAS Programming Professionals,

Did you know that you can create a SAS data set in another operating system's internal data representation format? 

For example, you might be running SAS on Windows and want to create a UNIX SAS data set in a Windows directory for later delivery to a UNIX system.  You can do this using either the OUTREP data set option or the OUTREP LIBNAME option.  Here are examples of both options:

options msglevel=I;

/* Two examples of using the OUTREP LIBNAME option */

libname UNIXDATA "C:\TEMP\UNIXDATA" outrep=hp_ux;

/* 1. Creating a new SAS data set in the "Foreign" data library */

data UNIXDATA.class;
set  sashelp.class;
run;

proc contents data=UNIXDATA.class;
run;

/* 2. Copying a SAS data set to the "Foreign" data library */
proc copy in=sashelp out=UNIXDATA noclone;
      select prdsale;
run;

proc contents data=UNIXDATA.prdsale;
run;

/* 3. Using the OUTREP data set option */

libname UNIXDATA clear;

libname UNIXDATA "C:\TEMP\UNIXDATA";

data UNIXDATA.orsales(outrep=hp_ux);
set  sashelp.orsales;
run;

proc contents data=UNIXDATA.orsales;
run;

In the first LIBNAME OUTREP option example, the newly created CLASS data set will be in HP-UX format, even though it is stored on a Windows directory.  Check out the Data Representation field in the CONTENTS listing.

In the second LIBNAME OUTREP option example, the PRDSALE data set will be in HP-UX format.  But, notice that when the COPY procedure is executed, SAS normally "CLONE"-s the format of the input data set to the output data set.  So, you need to use the NOCLONE option for the new data set (UNIXLIB.PRDSALE) to be in HP-UX format.

The final example illustrates how you can code OUTREP data set option to store UNIXDATA.ORSALES as a UNIX SAS data set, even though it is stored in a Windows directly--as specified in the LIBNAME statement.

Note that with the MSGLEVEL=I option enabled, you will see the following type of message in your SAS log:

INFO: Data file UNIXDATA.CLASS.DATA is in a format that is native to another host, or the file encoding does not match the session encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce performance.


That message lets you know that you have, indeed, been successful in storing a SAS data set in a foreign host’s data representation.  Good job!

Best of luck in all your SAS endeavors!

---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers