Help using Base SAS procedures

basic questions on how to interpret some codes

Reply
Contributor
Posts: 30

basic questions on how to interpret some codes

Hi,

I'm a beginner studying with SAS certification prep guide textbook for Base Programming for SAS9 exam.

After reading textbook several times, there are some codes that I don't quite understand their usages, so it would be very helpful if someone could interpret codes in bold characters in a normal language to help me understand their meanings more fully.

I provided my interpretation of codes on the right hand-side whenever I think I understood them.

Chapter 7 pp241 (Creating and applying user defined formats)

libname library 'c:\sas\formats\lib';                                        Create a libname library to a specified lotion where the format catalog will be stored???

proc format library=library fmtlib;                                          

run;

Also, (proc format library=) and (proc format lib=) have the exact same meaning?

Chapter 11 pp339 (usage of the FIRST and LAST observation in a group)

proc sort data=company.usa out=work.temp;                         Sort data in a file usa by a variable dept and create a temporary file temp         

     by dept;

run;

data company.budget (keep=dept payroll);                              Create a data file called budget under libref company and keep a variable dept and payroll

     set work.temp;                                                                 Read data from a temporary file called temp

     by dept;                                                                           Group data by a variable dept

     if wagecat='S' then Yearly=wagerate*12;                             If variable wagecat equals S, then place calculation result of wagerate multiplied by 12 in Yearly

     else if wagecat='H' then Yearly=wagerate*2000;                   If variable wagecat equals H, then place calculation result of wagerate multiplied by 2000 in Yearly

    if first.dept then payroll=0;

     payroll+yearly;                                                                 

     if last.dept;

run;

Contributor
Posts: 22

Re: basic questions on how to interpret some codes

1. libname is to create a library for storing format, with the library name as "library".   The book also confused me when it define library name as "library".  It's better use some string other than the keywords, e.g. libname mylib "......

2. yes, (proc format library=) and (proc format lib=) are same thing. lib= is abbrevation for library=

3. FMTLIB is used for display format in a catalog only

4. for data company.budget ....part,

if first.dept then payroll=0 ;              /*for the first row of each group of dept variable, set payroll=0. NOTE this IF is for condition*/

payroll+yearly;                                /*equivallent to   payroll=payroll+yearly,   i.e. to accumulate yearly to payroll variable.  NOTE this applies to any rows*/

if last.dept;                                      /*only keep the last row of each group of dept variable.    NOTE this IF is for subsetting*/

Contributor
Posts: 30

Re: basic questions on how to interpret some codes

Hi Ping,

Thank you very much for your quick response!

Your answer really clarified my doubts.

Merry Christmas and have a great holiday.

All the best,

Hatsumi

Super User
Super User
Posts: 6,500

Re: basic questions on how to interpret some codes

LIBNAME statements define the nicknames or librefs that are used to refer to permanent datasets and catalogs.  They associate the libref with the physical location.  Note the use of LIBRARY as the libref.  By default SAS will look for user defined formats in that catalog LIBRARY.FORMATS. You can override this by specifying the catalogs you want to use instead with the FMTSEARCH option.

FMTLIB option tells PROC FORMAT to print out the format definitions.  LIB= is alias for LIBRARY= option.  In this case since only a libref is given the proc will look for a catalog named LIBRARY.FORMATS.  If you want to use a format catalog with a different name then use a two level name as the value for the LIB= option.

   if first.dept then payroll=0;

     payroll+yearly;                                                                

     if last.dept;

This block will sum the variable YEARLY into the variable PAYROLL.  It restarts the sum at 0 when a new department begins.  Retains the value of PAYROLL from observation to observation and outputs only one observations for each value of DEPT.

Note that PAYROLL+YEARLY is an example of a sum statement. It is equivalent to these two statements:

  retain payroll 0;

  payroll = sum(payroll,yearly) ;

Note that IF LAST.DEPT is an example of a subsetting if statement.  It is the equivalent of  IF NOT ( last.dept) THEN DELETE ;

Contributor
Posts: 72

Re: basic questions on how to interpret some codes

Hi Tom,

Merry christmas to you,

I have often noticed a lot of your amazing solutions for so many different questions. I would like to ask "what does it take to become a Great expert like you, How long? what approach in learning?Books, forums, nesug papers and what others besides instructed led training? Can you offer some tips, so younger wannabe Tom's can try?

Have a wonderful christmas,

Mark

Super User
Super User
Posts: 6,500

Re: basic questions on how to interpret some codes

Play. 

Read the manuals and experiment with what you can do with the statement.s

Contributor
Posts: 30

Re: basic questions on how to interpret some codes

Hi Tom,

Thank you very much for your detailed answer in such a short turn around during the busy season!

Merry Christmas and I hope you are enjoying your holiday.

All the best,

Hatsumi

Ask a Question
Discussion stats
  • 6 replies
  • 376 views
  • 6 likes
  • 4 in conversation