![]() |
![]() |
Examples of SAS/ACCESS DATA Step Programs |
This example illustrates how to use an input SAS data set as a transaction file to supply parameter values for direct access DML calls. These calls obtain CA-IDMS records using CALC key values. The transaction data set WORK.EMP supplies CALC key values for EMPLOYEE records. The program then accesses EMPOSITION records in the EMP-EMPOSITION set to create an output SAS data set that contains all of the position information for the employees named in WORK.EMP. The DATA step terminates after all observations from WORK.EMP have been read. The numbers in the program correspond to the numbered comments following the program.
1 *options $idmdbug; 2 data work.emp; input id $4.; datalines; 0471 0301 0004 0091 1002 ; data work.emp_empos; drop id chkrec nxtrec; length chkrec $ 29; 3 infile empss01 idms func=func record=recname ikeylen=keyl errstat=stat sequence=seq set=inset ikey=ckey dbkey=dkey; /* BIND the records to be accessed */ 4 if _n_ = 1 then do; func = 'BIND'; recname = 'EMPLOYEE'; input; if stat ne '0000' then go to staterr; recname = 'EMPOSITION'; input; if stat ne '0000' then go to staterr; end; /* OBTAIN EMPLOYEE records using CALC key */ /* from EMP data set */ 5 set work.emp; func = 'OBTAIN'; ckey = id; keyl = 4; recname = 'EMPLOYEE'; input @; if stat not in ('0000', '0326') then go to staterr; if stat = '0000' then do; input @1 employee_id 4.0 @5 firstname $char10. @15 lastname $char15. @30 street $char20. @50 city $char15. @65 state $char2. @67 zip $char9. @76 phone 10.0 @86 status $char2. @88 ssnumber $char9. @97 emp_start yymmdd6. @103 emp_term 6.0 @109 birthdate yymmdd6.; /* OBTAIN LAST EMPOSITION record in */ /* EMP-EMPOSITION set */ 6 func = 'OBTAIN'; seq = 'LAST'; ckey = ' '; keyl = 0; dkey = ' '; recname = 'EMPOSITION'; inset = 'EMP-EMPOSITION'; input @; if stat not in ('0000', '0326') then go to staterr; if stat = '0000' then do; chkrec = put(employee_id,z4.) ||firstname || lastname; /* Process all EMPOSITION records for */ /* current EMPLOYEE */ 7 do until (nxtrec = chkrec); input @1 pos_start yymmdd6. @7 pos_finish 6.0 @13 salarygrade 2.0 @15 salary pd5.2 @20 bonus pd2.0 @22 commission pd2.0 @24 overtime pd2.0; output; /* ACCEPT CURRENCY for PRIOR record in */ /* EMP-EMPOSITION set */ 8 func = 'ACCEPT'; dkey = ' '; seq = 'PRIOR '; recname = ' '; inset = 'EMP-EMPOSITION'; input; if stat eq '0000' then do; /* OBTAIN current record using the DBKEY */ 9 func = 'OBTAIN'; seq = ' '; inset = ' '; input @1 nxtrec $29. @; if stat ne '0000' then go to staterr; end; end; end; 10 else do; put 'WARNING: No EMPOSITION record for EMPID= ' id; put 'WARNING: Execution continues with next EMPID.'; _error_ = 0; end; end; else do; put 'WARNING: No EMPLOYEE record for EMPID= ' id; put 'WARNING: Execution continues with next EMPID.'; _error_ = 0; end; return; 11 staterr: put @1 'ERROR: ' @10 func @17 'RETURNED STATUS =' @37 stat; put @1 'ERROR: INFILE parameter values are: '; put @1 'ERROR: ' recname= ckey= seq= inset= keyl= dkey=; put @1 'ERROR: DATA step execution terminating.'; _error_ = 0; stop; run; proc print data=work.emp_empos; format emp_start birthdate pos_start date9. salary dollar12.2 title1 'Positions Held by Specified Employees'; title2 'Listed in Ascending Order by Initdate/Termdate'; run;
| |
| |
| |
| |
| |
| |
The input buffer already contains an EMPOSITION record. The INPUT statement maps EMPOSITION data from the held buffer into the variables in the PDV. At this point, a complete observation exists and is output to the WORK.EMP_EMPOS data set. No observation is written when no EMPOSITION records exist for a specified employee. | |
| |
| |
| |
|
The following output shows a portion of the output from this program.
Using a SAS Data Set as a Transaction File
Positions Held by Specified Employees Listed in Ascending Order by Initdate/Termdate employee_ Obs id firstname lastname street city state 1 471 THEMIS PAPAZEUS 234 TRANSWORLD ST NORTHBORO MA 2 471 THEMIS PAPAZEUS 234 TRANSWORLD ST NORTHBORO MA 3 301 BURT LANCHESTER 45 PINKERTON AVE WALTHAM MA 4 301 BURT LANCHESTER 45 PINKERTON AVE WALTHAM MA 5 301 BURT LANCHESTER 45 PINKERTON AVE WALTHAM MA 6 4 HERBERT CRANE 30 HERON AVE KINGSTON NJ 7 4 HERBERT CRANE 30 HERON AVE KINGSTON NJ 8 4 HERBERT CRANE 30 HERON AVE KINGSTON NJ 9 91 MADELINE ORGRATZI 67 RAINBOW DR KENDON MA Obs zip phone status ssnumber emp_start emp_term birthdate pos_start 1 03256 6174561277 01 022887770 07SEP1978 0 04MAR1935 07SEP1978 2 03256 6174561277 01 022887770 07SEP1978 0 04MAR1935 01JAN1982 3 01476 6175341109 01 129040506 03FEB1975 0 19APR1932 03FEB1975 4 01476 6175341109 01 129040506 03FEB1975 0 19APR1932 03FEB1977 5 01476 6175341109 01 129040506 03FEB1975 0 19APR1932 03FEB1980 6 21341 2013341433 01 016777451 14MAY1977 0 21MAR1942 14MAY1977 7 21341 2013341433 01 016777451 14MAY1977 0 21MAR1942 15NOV1979 8 21341 2013341433 01 016777451 14MAY1977 0 21MAR1942 14MAY1982 9 06182 6174311919 01 231067878 10OCT1980 0 16OCT1951 10OCT1980 pos_ Obs finish salarygrade salary bonus commission overtime 1 811231 72 $90,000.00 10 0 0 2 0 82 $100,000.00 10 0 0 3 770202 52 $39,000.00 7 0 0 4 800202 52 $45,000.00 7 0 0 5 0 53 $54,500.00 7 0 0 6 791114 71 $60,000.00 10 0 0 7 820513 71 $70,000.00 10 0 0 8 0 71 $75,000.00 10 0 0 9 0 43 $39,000.00 7 0 0
![]() |
![]() |
Copyright © 2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.