Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
SASTechies [email_address] http://www.sastechies.com
<ul><li>DATA steps  typically create or modify SAS data sets, but they can also be used to produce custom-designed reports...
<ul><li>Data numbers; </li></ul><ul><li>X1=1;  </li></ul><ul><li>x2=2; </li></ul><ul><li>Run; </li></ul><ul><li>Proc print...
<ul><li>C, C++, Java like syntax </li></ul><ul><li>Every Statement ends with ; </li></ul><ul><li>Datastep starts with the ...
<ul><li>Log would show the entire program with the Run time i.e. Real time and the CPU Time. </li></ul><ul><li>Any errors ...
<ul><li>Output Window would show the output of the Procedure in a Listing or HTML Format, date, time and SAS System messag...
<ul><li>To define a library, you assign it a  library name  and specify a  path   </li></ul><ul><li>Libname libref “C:	emp...
SAS file in any library  except Work  indicates that the SAS file is stored permanently  SAS Techies  2009 11/13/09 Perman...
<ul><li>Datalines / cards statement </li></ul><ul><li>-- Indicates that data lines follow </li></ul>SAS Techies  2009 11/1...
<ul><li>Set Statement </li></ul><ul><li>--Reads an observation from one or more already existing SAS data sets </li></ul><...
<ul><li>a SAS data set is a file consisting of two parts: a  descriptor portion  and a  data portion   </li></ul><ul><li> ...
<ul><li>Variable names must ---- </li></ul><ul><ul><li>be 1 to 32 characters in length  </li></ul></ul><ul><ul><li>begin w...
SAS Techies  2009 11/13/09 Description Default Length Max Length Variable Name <32 32 characters Value  CHAR NUM 8 bytes 8...
SAS Techies  2009 11/13/09 <ul><li>Variable Type and Missing Values   </li></ul><ul><li>A variable's type determines how S...
<ul><li>Informats  Informats determine how data values are read into a SAS data set. You  must  use informats to read nume...
<ul><li>Formats  write values out using some particular form. </li></ul><ul><li>User defined formats </li></ul><ul><li>pro...
<ul><li>Contents Procedure  </li></ul><ul><ul><li>PROC CONTENTS DATA= libref._ALL_ NODETAILS; </li></ul></ul><ul><ul><li>R...
<ul><li>To modify system options, you submit an OPTIONS statement.  </li></ul><ul><li>OPTIONS statement is  global , the s...
Default Yearcutoff=1920 SAS Techies  2009 11/13/09 Date Expression Interpreted As 12/07/41 18Dec15 04/15/30 15Apr95 12/07/...
<ul><li>Assignment statements </li></ul><ul><li>X1=1; X2=2; X3=X2-X1; </li></ul><ul><li>Note: In the second case if either...
<ul><li>To create a variable that accumulates values down observations, a  sum statement  in a DATA step is used. </li></u...
<ul><li>To assign a length to a variable </li></ul><ul><li>Ex: Length var1 $ 10 var2 10; </li></ul><ul><li>Where used: </l...
<ul><li>Error Types </li></ul><ul><ul><li>Syntax Errors -  occur when program statements do not conform to the rules of th...
SAS Techies  2009 11/13/09
SAS Techies  2009 11/13/09 NOTE: Invalid data for RecHR in line 14 35-37.   RULE: ----+----1----+----2----+----3----+----4...
Upcoming SlideShare
Loading in …5
×

Basics Of SAS Programming Language

85,628 views

Published on

Learning
Base SAS,
Advanced SAS,
Proc SQl,
ODS,
SAS in financial industry,
Clinical trials,
SAS Macros,
SAS BI,
SAS on Unix,
SAS on Mainframe,
SAS interview Questions and Answers,
SAS Tips and Techniques,
SAS Resources,
SAS Certification questions...

visit http://sastechies.blogspot.com

Published in: Technology
  • Hi All, We provide Salesforce training in a traditional Classroom setting at our training center where students gain hands-on training from our Salesforce Instructor as well as interact with other students. Classroom settings provide you a high level of retention and allow collaboration to encourage peer insight and team building. For more information feel free to contact us : siva@keylabstraining.com. For Course Content and Recorded Demo Click Here : http://www.keylabstraining.com/salesforce-online-training-hyderabad-bangalore
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • fix formatting
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Basics Of SAS Programming Language

  1. 1. SASTechies [email_address] http://www.sastechies.com
  2. 2. <ul><li>DATA steps typically create or modify SAS data sets, but they can also be used to produce custom-designed reports. For example, you can use DATA steps to </li></ul><ul><ul><li>put your data into a SAS data set </li></ul></ul><ul><ul><li>compute the values for new variables </li></ul></ul><ul><ul><li>check for and correct errors in your data </li></ul></ul><ul><ul><li>produce new SAS data sets by sub-setting, merging, and updating existing data sets. </li></ul></ul><ul><li>PROC (procedure) steps typically analyze and process data in the form of a SAS data set, and they sometimes create SAS data sets that contain the results of the procedure. PROC steps control a library of prewritten routines (procedures) that perform tasks on SAS data sets, such as listing, sorting, and summarizing data. For example, you can use PROC steps to </li></ul><ul><ul><li>print a report </li></ul></ul><ul><ul><li>produce descriptive statistics </li></ul></ul><ul><ul><li>create a tabular report </li></ul></ul><ul><ul><li>produce plots and charts. </li></ul></ul>SAS Techies 2009 11/13/09
  3. 3. <ul><li>Data numbers; </li></ul><ul><li>X1=1; </li></ul><ul><li>x2=2; </li></ul><ul><li>Run; </li></ul><ul><li>Proc print data=numbers; </li></ul><ul><li>Run; </li></ul><ul><li>Start of a Datastep </li></ul><ul><li>Assigning values to x1 x2 </li></ul><ul><li>End the datastep </li></ul><ul><li>Issue a Print Procedure to print the dataset numbers </li></ul><ul><li>End the Run statement </li></ul>SAS Techies 2009 11/13/09
  4. 4. <ul><li>C, C++, Java like syntax </li></ul><ul><li>Every Statement ends with ; </li></ul><ul><li>Datastep starts with the keyword data followed by the dataset name. </li></ul><ul><li>Datastep ends when run; is found or any other Data or Proc is found else the Status on the window would show “Datastep or Proc Running” </li></ul><ul><li>It usually begins with a SAS keyword </li></ul><ul><li>they can begin and end anywhere on a line </li></ul><ul><li>one statement can continue over several lines </li></ul><ul><li>several statements can be on a line. </li></ul>SAS Techies 2009 11/13/09
  5. 5. <ul><li>Log would show the entire program with the Run time i.e. Real time and the CPU Time. </li></ul><ul><li>Any errors or any output with PUT or Macro statements </li></ul>SAS Techies 2009 11/13/09
  6. 6. <ul><li>Output Window would show the output of the Procedure in a Listing or HTML Format, date, time and SAS System message. </li></ul><ul><li>Results Window would show any results produced </li></ul><ul><li>Explorer window would show any dataset prepared in that step. </li></ul>SAS Techies 2009 11/13/09
  7. 7. <ul><li>To define a library, you assign it a library name and specify a path </li></ul><ul><li>Libname libref “C: emp”; </li></ul><ul><li>Open the library in Explorer would show all </li></ul><ul><ul><li>Datasets </li></ul></ul><ul><ul><li>Catalogs </li></ul></ul><ul><ul><li>macro compilation </li></ul></ul><ul><ul><li>views </li></ul></ul><ul><li>When you delete a library you delete the reference to SAS engine and Not the Contents at that path. To delete the contents select all of them and delete. </li></ul><ul><li>Note: libref is 1 to 8 characters long only and remain in effect until you modify them, cancel them, or end your SAS session </li></ul>SAS Techies 2009 11/13/09
  8. 8. SAS file in any library except Work indicates that the SAS file is stored permanently SAS Techies 2009 11/13/09 Permanent SAS Files                                                 Clinic . Admit Clinic . Admit2          Temporary SAS File                      Work . Test Temporary SAS File, One-Level Name                                 Test
  9. 9. <ul><li>Datalines / cards statement </li></ul><ul><li>-- Indicates that data lines follow </li></ul>SAS Techies 2009 11/13/09
  10. 10. <ul><li>Set Statement </li></ul><ul><li>--Reads an observation from one or more already existing SAS data sets </li></ul><ul><li>-- used to copy / subset of observations to perform additional operations. </li></ul><ul><ul><ul><ul><li>Data work.ins; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>set clinic.insure(where=(weight>150)); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>if weight > 150 then Overweight=‘Yes’; run; </li></ul></ul></ul></ul>SAS Techies 2009 11/13/09
  11. 11. <ul><li>a SAS data set is a file consisting of two parts: a descriptor portion and a data portion </li></ul><ul><li> </li></ul>SAS Techies 2009 11/13/09 Data Set Name: CLINIC.INSURE Member Type: DATA Engine: V8 Created: 10:05 Tuesday, March 30, 1999 Observations: 21 Variables: 7 Indexes: 0 Observation Length: 64     Name   Sex     Age     Weight     Jones    M    48    128.6   Laverne      M    58    158.3   Jaffe    F   .    115.5   Wilson    M    28    170.1
  12. 12. <ul><li>Variable names must ---- </li></ul><ul><ul><li>be 1 to 32 characters in length </li></ul></ul><ul><ul><li>begin with a letter (A-Z, including mixed case characters) or an underscore (_) </li></ul></ul><ul><ul><li>continue with any combination of numbers, letters, or underscores. </li></ul></ul>A variable's type is either character or numeric . SAS Techies 2009 11/13/09 Name ------ Policy Total Name Type ---- Num Num Char Length ----- 8 8 20 Format --------- DOLLAR8.2 Informat -------- COMMA10. Label ------------- Policy Number Total Balance Patient Name
  13. 13. SAS Techies 2009 11/13/09 Description Default Length Max Length Variable Name <32 32 characters Value CHAR NUM 8 bytes 8 bytes 32767 (32Kb) any bytes
  14. 14. SAS Techies 2009 11/13/09 <ul><li>Variable Type and Missing Values </li></ul><ul><li>A variable's type determines how SAS software displays missing values for a variable. </li></ul><ul><li>For character variables such as Name (shown below), a blank represents a missing value. </li></ul><ul><li>For numeric variables such as Age (shown below), a period represents a missing value. </li></ul>Missing         values     Name   Sex    Age    Weight       M    48    128.6   Laverne     M    58    158.3   Jaffe    F   .    115.5   Wilson    M    28    170.1
  15. 15. <ul><li>Informats Informats determine how data values are read into a SAS data set. You must use informats to read numeric values that contain letters or other special characters. </li></ul>SAS Techies 2009 11/13/09 $ASCII w . DATE w . NENGO w . $BINARY w . DATETIME w . PD w.d $VARYING w . HEX w . PERCENT w . $ w . JULIAN w . TIME w . COMMA w.d MMDDYY w . w.d
  16. 16. <ul><li>Formats write values out using some particular form. </li></ul><ul><li>User defined formats </li></ul><ul><li>proc format lib=library; </li></ul><ul><li>value JobFmt * if format is char then $ Jobfmt ; </li></ul><ul><li>103='manager' </li></ul><ul><li>105='text processor‘; </li></ul><ul><li>run; </li></ul><ul><li>Applied like -- format var Jobfmt . Var2 dollar11.2 ; </li></ul><ul><li>These are utilized to look up as if it were a table. </li></ul>SAS Techies 2009 11/13/09
  17. 17. <ul><li>Contents Procedure </li></ul><ul><ul><li>PROC CONTENTS DATA= libref._ALL_ NODETAILS; </li></ul></ul><ul><ul><li>RUN; </li></ul></ul>SAS Techies 2009 11/13/09
  18. 18. <ul><li>To modify system options, you submit an OPTIONS statement. </li></ul><ul><li>OPTIONS statement is global , the settings remain in effect until you modify them or end your SAS session. </li></ul>SAS Techies 2009 PROC OPTIONS < option(s)>; RUN; Proc options option=firstobs value; run; 11/13/09 Number|NoNumber Date|nodate Pageno Pagesize Linesize Mprint Mlogic Symbolgen Compress=yes|no BYLINE|NOBYLINE DETAILS|NODETAILS FIRSTOBS= FORMCHAR= FORMDLIM= LABEL|NOLABEL OBS= REPLACE|NOREPLACE SOURCE|NOSOURCE
  19. 19. Default Yearcutoff=1920 SAS Techies 2009 11/13/09 Date Expression Interpreted As 12/07/41 18Dec15 04/15/30 15Apr95 12/07/1941 18Dec2015 04/15/1930 15Apr1995 Date Expression SAS Date Informat Interpreted As 06Oct59 date7. 06Oct1959 17Mar1783 date9. 17Mar1783
  20. 20. <ul><li>Assignment statements </li></ul><ul><li>X1=1; X2=2; X3=X2-X1; </li></ul><ul><li>Note: In the second case if either X2 or X1 is missing then the value of X3 is missing. </li></ul><ul><li>You can create a variable (not macro variables) in a Datastep only. </li></ul><ul><li>Ex: data new; x=‘abc’; run; </li></ul>SAS Techies 2009 11/13/09
  21. 21. <ul><li>To create a variable that accumulates values down observations, a sum statement in a DATA step is used. </li></ul><ul><li>Note -- missing values are ignored. </li></ul><ul><li>Equivalent to function Sum(x1,x2,….) </li></ul><ul><li>Ex: If dsn some has y values </li></ul><ul><li>Data new; Y - 10,20,30 then </li></ul><ul><li>set some; </li></ul><ul><li>X+y; X - 10,30,60 </li></ul><ul><li>run; </li></ul>SAS Techies 2009 11/13/09
  22. 22. <ul><li>To assign a length to a variable </li></ul><ul><li>Ex: Length var1 $ 10 var2 10; </li></ul><ul><li>Where used: </li></ul><ul><li>data finance.newloan; </li></ul><ul><li>set finance.records(drop=amount rate); TotalLoan+payment; </li></ul><ul><li>if code='1' then Type='Fixed'; </li></ul><ul><li>else Type='Variable'; run; </li></ul><ul><li>Output will have Type=‘Varia’ </li></ul>SAS Techies 2009 11/13/09
  23. 23. <ul><li>Error Types </li></ul><ul><ul><li>Syntax Errors - occur when program statements do not conform to the rules of the SAS language </li></ul></ul><ul><ul><li>Data Errors - occur when some data values are not appropriate for the SAS statements that are specified in a program </li></ul></ul>SAS Techies 2009 11/13/09
  24. 24. SAS Techies 2009 11/13/09
  25. 25. SAS Techies 2009 11/13/09 NOTE: Invalid data for RecHR in line 14 35-37. RULE: ----+----1----+----2----+----3----+----4----+----5--- 14 2575 Quigley, M 74 152 Q13 11 26 I ID=2575 Name=Quigley, M RestHR=74 MaxHR=152 RecHR=. TimeMin=11 TimeSec=26 Tolerance=I _ERROR_=1 _N_=14 NOTE: 21 records were read from the infile TESTS. The minimum record length was 45. The maximum record length was 45. NOTE: The data set CLINIC.STRESS has 21 observations and 8 variables. NOTE: DATA statement used: real time 2.04 seconds cpu time 0.06 seconds

×