1 / 15

SAS Tips & Techniques

SAS Tips & Techniques. Prepared by: Luigi Muro – Consultant Bell Canada. Tips & Techniques. Tip # 1: Optimization of Data Step GOAL: Reduce the number of data steps required to perform a task. In Create a 1 Flat file containing samples from 2 SAS files. put Files Statistics:

svea
Download Presentation

SAS Tips & Techniques

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SAS Tips & Techniques Prepared by: Luigi Muro – Consultant Bell Canada

  2. Tips & Techniques Tip # 1: Optimization of Data Step GOAL: Reduce the number of data steps required to perform a task. In Create a 1 Flat file containing samples from 2 SAS files. put Files Statistics: INPUT1 Number of Records: 2.7 Millions Number of Variables: 52 Variable Length: 257 INPUT2 Number of Records: 4.2 Millions Number of Variables: 52 Variable Length: 257

  3. Tips & Techniques

  4. Tips & Techniques Solution 2 (More Efficient, reduce the number of steps) Data _Null_ ; Set input1.indices(Keep=VAR: where=(ranbin(0, 1, 0.01))) input2.indices(Keep=VAR: where=(ranbin(0, 1, 0.25))) ; File output delimiter=”;”; format var: 8.6; Put … ; Run ; Note: No output file is created. (Not needed since the required output is a flat file) Version 6 (Delimiter option not available) : Put (var:) (8.6,';') ;

  5. Tips & Techniques Tip # 2: Use a SAS procedure to replace many Data Steps GOAL: Produce a sales report: Percent sales by product.

  6. Tips & Techniques

  7. Tips & Techniques

  8. Tips & Techniques Tip # 3: Send an E-mail from SAS (SAS V8) filenamedoemailemail to=('joe.doe@bell.ca' 'jane.doe@bell.ca') cc='gino.tremblay@sympatico.ca' subject='New Transaction File. ' attach='Filename.xls'; data _null_; file doemail; put 'Please note that a new transaction file is available'; run; Note: the following statements must be added to Sasv8.cfg or at invocation -emailsys SMTP or MAPI -emailhost “your.smtp_server.host” (mailserver.bell.ca)

  9. Tips & Techniques Tip # 4 Passing parameters to SAS with SYSPARM option. MVS – (Batch) //RUNSAS EXEC SAS,OPTIONS=“SYSPARM=QUE” //SYSIN DD * %let province = &sysparm; Unix/Windows Batch session SAS -sysin ‘pgm.sas’ -log ‘pgm.log’ -sysparm ‘QUE’ Data _null_; Province = “&sysparm”; Run;

  10. Tips & Techniques Tip # 5. Dates and Strings Manipulations GOAL: List of working days for next week (Exclude Sat. and Sun.). Data _null_; LENGTH datestr $50; DateStr=‘['; DO Dt = (TODAY()) TO (TODAY() + 6) by 1; IF (1 LT WEEKDAY(Dt) LT 7) THEN DateStr=TRIM(DateStr) || PUT(Dt,Date7.) !! ','; END; SUBSTR(DateStr,LENGTH(TRIM(DateStr)),1)=‘]'; CALL SYMPUT(‘Datestr',TRIM(DateStr)); STOP; Run; &Datestr contains [12NOV03,13NOV03,14NOV03,17NOV03,18NOV03]

  11. orders prices customers PartNumber Quantity CustomerID PartNumber UnitPrice Company Address City State CustomerID Tips & Techniques Tip # 6 Use SQL procedure to simplify Merge. GOAL: Merge 3 SAS data sets that do not have a common BY variable.

  12. Tips & Techniques

  13. Tips & Techniques Solution # 2 (Proc SQL) proc sql; select a.CustomerID, Company, Address, b.PartNumber, Quantity, Quantity*UnitPrice as Sale from Customers as a, Prices as b, Orders as c where a.CustomerID = c.CustomerID and b.PartNumber = c.PartNumber order by Company ; quit;

  14. Tips & Techniques Tip # 7a – Use SAS Views to Optimize process (Input views)

  15. Tips & Techniques Tip # 7b – Use SAS Views to Optimize process (Output views) Data_null_ / view=file3; length field1 $ 10 field2 $10 acct $20 balance 8 . . .; set file3; File OUT; Put var1 var2… ; run; proc sort data=file1 out=file3; by balance; run;

More Related