Professional Documents
Culture Documents
Paper 211-25 SAS® For COBOL (And Other) Programmers: How To: Doug Zirbel, Modis, Inc., Bloomington, MN
Paper 211-25 SAS® For COBOL (And Other) Programmers: How To: Doug Zirbel, Modis, Inc., Bloomington, MN
Paper 211-25 SAS For COBOL (and Other) Programmers: How To Doug Zirbel, Modis, Inc., Bloomington, MN
ABSTRACT
For all its power and behind-the-scenes success, SAS software is still unknown to many programmers and I/T management. This paper provides tools you can use to solve this problem in your company or area by offering a short SAS class which gets programmers up and running quickly. Q: Can I call a subroutine like I can in COBOL? A: Yes, with CALL MODULE(subroutinename,arg1,arg2). Q: Can I do string functions just like everything I can do with INSPECT? A: SAS offers a wide range of character functions. For example, FLD1=TRANSLATE(FLD1,TO-CHARACTERS,FROMCHARACTERS) Q: Can I use SAS instead of COBOL for on-line transaction processing (OLTP) with CICS? A: SAS has no provision for this, and although SAS / AF is screen-based, it is better suited to on-line analytical processing (OLAP). Q: Can I get a randomly-generated subset of 100 recs from a 2,000,000-rec input file for testing purposes? A: You can do it with one line of code. To do so in COBOL would require a more complex subroutine or paragraph. Check out the RANUNI function in the SAS Language manual. Example: IF RANUNI(0) LE 0.00005 THEN OUTPUT; Q: Can I write Windows or Unix graphics-based screens to access my mainframe data? A: Yes. Thats SAS/AF, but out of the scope of an introductory mainframe-based course. Q: How do I find out exactly what Ive got installed at my site? A: In SAS Data Manager or in batch, run PROC SETINIT;
INTRODUCTION
SAS software is widely used in the mainframe Information Technology world. It is the eighth-largest software company in the world. It has won awards. Yet if you have used SAS software in this environment, you may find yourself having to explain to your colleagues what SAS is. However, by offering a short class even as brown bag lunch sessions to programmers who arent familiar with SAS, you can go a long way toward answering that question. From my experience teaching such classes and from the advice and feedback of attendees and others, I can offer several tools you might be able to use in developing a custom SAS course at your site. They are: 1) FAQs (Frequently-asked-questions) about SAS 2) Myths about SAS 3) Feedback from previous students and others 4) Charts of COBOL / SAS similarities
FAQs
Q: Can I load VSAM files? A: Use OPTION VSAMLOAD=YES; Q: Can I do a transaction-master (external) file update, just like in COBOL? A: Yes, use a Data _null_; program with INFILE, INPUT, FILE, PUT, and IF statements. Q: Can I do a transaction-master SAS file update, just like in COBOL? A: Yes, use either MERGE, UPDATE, or MODIFY statements, or PROC SQL. Q: Can I read Roman numerals just like other numbers?? A: No. But, you can write them with the ROMANw. format! Q: Can I get SAS at Best Buy? A: No. Call your local SAS office. Q: Can I use SAS along with SyncSort, FileAid, EZTrieve, awk, REXX, CLIST, Lotus Notes, JAVA, ODBC, IEBGENER, C++, VB, DB2, IMS, IDMS, Access, Excel and TCP/IP? A: Yes. And in some cases in place of.
Posters
Myth: SAS arrays are so different from COBOL tables that no COBOL knowledge can be applied to use them. Truth: SAS arrays are remarkably similar to COBOL tables. Myth: SAS its that statistical software isnt it? we wouldnt have any use for it here. Truth: SAS can do almost anything COBOL can do, with far less time spend coding. SASs statistical functionality is only one of the dozens of roles it fills.
CONTACT INFORMATION
Doug Zirbel Modis, Inc. Bloomington, MN zirbel@computerpro.com (218) 525-5518
ACKNOWLEDGEMENTS
I am especially grateful to Michael Sperling at the City of Phoenix, Phil Weiss at SAS Institute in Phoenix, many students, and SAS-L discussion group participants.
APPENDIX
(next pages)
CONCLUSION
Presenting a talk or a class on SAS at your worksite takes preparation and should be adapted to build on the existing knowledge of those who will attend. Make the advantages (and potential disadvantages) of SAS clear. Develop a handout which will be instantly useable long after most of the course has been forgotten.
TRADEMARKS
SAS is a registered trademark of SAS Institute Inc. in the USA and other countries.
REFERENCES
SAS Language: Reference, Version 6, First Edition, #C56076, Cary, NC: SAS Institute Inc. SAS Companion For The MVS Environment, #C55108, Cary, NC: SAS Institute Inc.
FILENAME xyz YOURTSO.TRANS.FILE DISP=SHR; FILENAME xyz /usr1/misc/trans.txt; FILENAME xyz c:\My Documents\trans.txt
READ TRANSFILE INTO WS-TRANS 01 WS-TRANS. 05 FIELD1 PIC X(18). 05 FIELD2 PIC X(6). 05 DATE1 10 YY PIC 99. 10 MM PIC 99. 10 DD PIC 99. WRITE MASTERFILE FROM WS-TRANS WRITE MASTERFILE IF condition-x cobol-verb(s) ELSE cobol-verb(s) ENDIF
INPUT @01 field1 @21 @28 INPUT @01 field1 @21 @28
$CHAR18. field2 $CHAR6. fld3 $CHAR4.; $CHAR18. field2 $CHAR6. date1 $YYMMDD6.;
FILE MSTRFILE; PUT _INFILE_; FILE MSTRFILE; PUT @01 field1 @25 field2 @120 fld3; IF x THEN DO; Sas-verbs END; ELSE DO; Sas-verbs END; LINK PROC2000; sas-verbs RETURN; PROC2000: ( thats a colon) sas-verbs RETURN; YTOTAL=TOT1 + XTOTAL; GRANDACM+TOT2; ARRAY A_GROUP(10) GROUP1-GROUP10; IF GENDER=M;
This particular example writes the output file from the whole WS-TRANS file This writes 3 fields to an output rec You can have multiple nested-ifs in both COBOL & SAS of course.
Where COBOL thrives on hierarchical structure, SAS prefers fall-through type logic. However, there are definitely times when its appropriate to do perform-type logic in SAS.
ADD TOT1 TO XTOTAL GIVING YTOTAL. ADD TOT2 TO GRAND-ACCUM. WS-A-GROUP OCCURS 10 TIMES.
STOP RUN.
RUN;
Similar for multiply, subtract, divide, etc. + - * / ** TOT2 varies with each input rec, but GRANDACM keeps getting bigger Much more flexible than can be shown here. Called a subsetting-if in SAS it means if your input recs GENDER var =M then keep the record for writing to output file, otherwise dont write it to the output file. SAS automatically stops processing when it gets to the end of input unless you tell it otherwise. RUN marks the end of the code or module, and also writes out 1 output rec, then returns to the top of the DATA statement to begin with the next input rec.
Posters
ABORT ABEND 16; B=A; NUMFLD1=A; WHERE (condition) IF VERIFY(FLD1,0123456789)=0; IF VERIFY (UPCASE(FLD1),ABCDEFGHIJKLMNOPQRSTUVWXYZ) =0;
This abends & sets RC=16 A stays the same in both COBOL and SAS (doesnt get wiped out). 0C7 in COBOL, but just an error message in a SAS log Can be used on SAS datasets in data steps and procsdoesnt need to be relational DBMS If a byte in the char fld FLD1 is not in 019 that bytes position number is returned Similar to above also, the UPCASE function makes any lower-case chars into upper-case
Posters
Posters