SAS Tips &amp; Techniques

1 / 15

SAS Tips & Techniques - PowerPoint PPT Presentation

SAS Tips &amp; Techniques. Prepared by: Luigi Muro – Consultant Bell Canada. Tips &amp; 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:

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

PowerPoint Slideshow about ' SAS Tips & Techniques' - svea

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

SAS Tips & Techniques

Prepared by: Luigi Muro – Consultant

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

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,\';\') ;

Tips & Techniques

Tip # 2: Use a SAS procedure to replace many Data Steps

GOAL: Produce a sales report: Percent sales by product.

Tips & Techniques

Tip # 3: Send an E-mail from SAS (SAS V8)

filenamedoemailemail

to=(\'[email protected]\' \'[email protected]\')

cc=\'[email protected]\'

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)

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;

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]

orders

prices

customers

PartNumber

Quantity

CustomerID

PartNumber

UnitPrice

Company

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.

Tips & Techniques

Solution # 2 (Proc SQL)

proc sql;

select a.CustomerID,

Company,

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;

Tips & Techniques

Tip # 7a – Use SAS Views to Optimize process (Input views)

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;