Sas tips techniques
This presentation is the property of its rightful owner.
Sponsored Links
1 / 15

SAS Tips & Techniques PowerPoint PPT Presentation


  • 104 Views
  • Uploaded on
  • Presentation posted in: General

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:

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.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

SAS Tips & Techniques

Prepared by:Luigi Muro – Consultant

Bell Canada


Tips techniques

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:

INPUT1Number of Records:2.7 Millions

Number of Variables:52

Variable Length:257

INPUT2Number of Records:4.2 Millions

Number of Variables:52

Variable Length:257


Tips techniques1

Tips & Techniques


Tips techniques2

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 techniques3

Tips & Techniques

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

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


Tips techniques4

Tips & Techniques


Tips techniques5

Tips & Techniques


Tips techniques6

Tips & Techniques

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

filenamedoemailemail

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

[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 techniques7

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 techniques8

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]


Tips techniques9

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.


Tips techniques10

Tips & Techniques


Tips techniques11

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;


Tips techniques12

Tips & Techniques

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


Tips techniques13

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;


  • Login