12-23-2013 08:59 AM
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;
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
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;
12-23-2013 11:36 AM
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*/
12-23-2013 12:19 PM
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;
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 ;
12-24-2013 03:45 AM
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,
12-24-2013 05:49 AM
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,