Showing posts with label SAS. Show all posts
Showing posts with label SAS. Show all posts

Saturday, August 23, 2025

SAS Mainframe - Create PIE Chart using SAS

With the proc chart procedure, the PIE statement will create the PIECHART. The size of a pie represents the percentage that of category of data. Since the output is in spool and not routed to any printer, it is not exact circular. 
By Default it looks bit elliptical which can be made round by specifying proper values using LPI statement. The pie's size is determined only by the SAS system options LINESIZE and PAGESIZE=. In the snippet above, LS and PS are the parameters which stands for Linesize and Pagesize.  
Code snippet:
 


O/P:





Wednesday, January 6, 2016

SAS in Mainframes(z/Os) - Connecting to DB2 from SAS in mainframes

This post is all about connecting DB2 from SAS in mainframe environment and using the result set for further processing. To call and connect to DB2 session we need the SQL proc to be called first using the statement PROC SQL. When used in a program we need to begin  the code with PROC SQL and end it with QUIT; In Between these two we can write our SQL codes to fetch the required data.
Without wasting much time lets check the first JCL used to connect to db2.



//TTYYTST  JOB(TEST),CLASS=I,MSGCLASS=X,MSGLEVEL=(1,1)
//                NOTIFY=&SYSUID
//STEP01  EXEC PROC=SAS,OPTIONS='  '
//WORK    DD SPACE=(CYL,(,500)),VOL=(,,,59)
//OUTFILE DD DSN=TEST.OUTPUT.SAS,
//                   DISP=(,CATLG,DELETE),
//                  DCB=(RECFM=FB,LRECL=122,BLKSIZE=000),
//                  UNIT=SYSDA,SPACE=(TRK,(500,500),RLSE)
//SYSIN     DD *
OPTION NOCENTER;
OPTION SORTLIB;
PROC SQL;                                     <== Starts here
CONNECT TO DB2 (SSID=DQAT);    <== DQAT is the db2 subsystem here  
   CREATE TABLE test AS                  <== test is the sas datset here.
        SELECT * 
         FROM CONNECTION TO DB2 (
select fname,
         lastname,
         dept_name,        
from  test01.dept
where student_id = 1 fetch first 5 rows only) ;

%PUT SQLXRC=&SQLXRC;
%PUT SQLMSG=&SQLMSG;
QUIT;

DATA STEP1;
SET TEST;
FILE OUTFILE DLM=',' ;
IF _N_=1 THEN DO;
PUT   'FIRST NAME,'
          'LAST NAME,'
          'DEPT NAME,'
;
END;
PUT  FNAME
          LASTNAME
         DEPT_NAME
;
//SYSPRINT DD SYSOUT=*
//*

JCL is self explanatory. %PUT SQLXRC and SQLMSG are the macros used to capture the DB2 return codes and error messages if any.

Friday, January 30, 2015

SAS in Mainframes(z/Os) Tutorial with examples - Use of CARD and DATALINES in SAS

The CARD or the DATALINES  statement is valid in the data step and is used to Read the real data values into the program. Generally while running the sas programs, we use an input file(a physical DASD file)  and give a reference to the Data step using INFILE keyword.
DATALINE is nothing but Reading the Data inline. We can also use the keyword CARD. Both are equivalent in terms of function. CARDS were used long back when punch cards were used in mainframe system.
Have a look into the sas program below.
//SAS       EXEC SAS                     
//WORK      DD SPACE=(CYL,(50,10),RLSE)  
//SYSIN     DD *                         
                                         
OPTION NOCENTER;                         
OPTION SORTLIB='';                       
                                         
  DATA COV;                              
  INPUT @23  ACCTTYPE $CHAR01.           
    @10  NMBER  $CHAR02.                 
    @24  ACCTNO   $CHAR10.               
     ;                                   
 DATALINES;                              
  111111111111111111112222222222233333333
  111111111111111111112222222222233333333
  111111111111111111112222222222233333333
  111111111111111111112222222222233333333
    ;                                    
 PROC PRINT DATA=COV;                             
   
 A very small program, but there is no input file in the JCL. We are reading the input data using the DATALINES keyword. IF we print the data we will get the same expected output.

Friday, December 19, 2014

SAS in Mainframes(z/Os) Tutorial with examples

This post is basically about how SAS reads the record and internally processes it.
To start with lets check some basic sas concepts which comes into play when ever you run a simple SAS program.
The two primary steps in a sas program
1. SAS DATA step
2. SAS PROC step

DATA steps typically create or modify SAS data sets. They can also be used to produce custom-designed reports. For example, you can use DATA steps to
put your data into a SAS data set
  • compute values
  • check for and correct errors in your data
  • produce new SAS data sets by subsetting, merging, and updating existing data sets. 

PROC (procedure)  steps are pre-written routines that enable you to analyze and process the data in a SAS data set and to present the data in the form of a report

For example, you can use PROC steps to
  • create a report that lists the data
  • produce descriptive statistics
  • create a summary report. 
Diagrammatically the program flow is like below:


SAS program flow

Feature of a SAS program:
  • It usually begins with a SAS keyword.
  • It always ends with a semicolon.

In the DATA step, we introduce the input file,ie the external file (supplied in the DD name in JCL in case of mainframe) to SAS. Data step begins with DATA keyword.Also we take declare the layout of the field. As an example,
DATA CUST;                    
  INFILE  CUSTPOL;            
  INPUT @23  ACCTNO   $CHAR01.
        @60  POLNO    $CHAR10.
        @76  STAT     $CHAR01.
        @224 POLEFFDT 8.      
        @240 APPRCDT  8.  
          ;
Here, i have highlighted the SAS keywords in blue.  CUST  will be the name of the sas Dataset which SAS will prepare internally once this step is executed.
INFILE CUSTPOL : Here the CUSTPOL is the name of the physical(external) file from which the data is to be read. INPUT will take only those  fields from the specific positions and only those fields will be present in the SAS dataset CUST.

The above SAS DATA step is processed in 2  phases.
A) Compilation phase: Each of the statements are checked for syntax errors. Once it completes,execution begins.
B) Execution phase: Data is read and executed unless otherwise coded.
Some of the terms which comes with SAS data processing (Just a bit of knowledge is good)are: 
Input Buffer:
During Compilation phase, an input buffer(memory area) is created to hold the records from file. It is created when the raw data is read. It is just a logical concept.
Program Vector Data:
When the data is read, SAS builds a data set in the memory(which is very much internal to SAS) known as SAS data set.
This Program Vector contains automatic variables that can be used to track the number of observations,and comes  handy in many ways.

1.   _N_ counts the number of times that the DATA step begins to execute.
2 .  _ERROR_ signals the occurrence of an error that is caused by the data during execution.
The default value is 0, which means there is no error. When one or more errors occur, the value is set to 1.


At the beginning of the execution phase, the value of _N_ is 1. Because there are no data errors, the value of _ERROR_ is 0.

When we define the DATA step, we should try to use the minimum variables. Unnecessary declaration of the variables makes the SAS internal dataset bigger which can lead to more execution time.

During execution, each record in the input raw data file is read, stored in the program data vector, and then written to the new data set as an observation.
At the end of the DATA step, several actions occur. First, the values in the program data vector are written to the output data set as the first observation.



Log Messages
Each time  SAS  executes its step, it writes log . In z/os environment, it will be written to SASLOG.Looks like below.  It shows the number of records read, the number of records which gets selected in the criteria and finally goes into sas dataset.

NOTE: 17430 records were read from the infile CUSTPOL.                
      The minimum record length was 600.                              
      The maximum record length was 636.                              
NOTE: The data set WORK.CUSTPOL has 5818 observations and 12 variables.
NOTE: The DATA statement used the following resources:                
      CPU     time -         00:00:00.07                              
      Elapsed time -         00:00:02.99                              
      EXCP count   - 5998                                             
      Task  memory - 4904K (148K data, 4756K program)                 
      Total memory - 17710K (3488K data, 14222K program)              
      Timestamp    - 12/19/2014 2:43:29 AM                            
NOTE: The address space has used a maximum of 876K below the line and 1

Monday, June 9, 2014

Pass data through PARM in SAS. "Build output filenames dynamically through SAS"

Suppose we want to build a SAS output file name which will have filename along with the current date,
Example: FNAME_D040414.CSV or .txt.
In this scenario, we need to pass the file name to SAS through PARM.

//STP10 EXEC SAS,PARM='SYSPARM="&NAME"'
//WORK      DD UNIT=WORK,SPACE=(CYL,(50,50),RLSE), 
//SASLOG    DD SYSOUT=*
//OUTCARD   DD DSN=&&OUTCRD,DISP=(NEW,PASS),
//SYSIN     DD DSN=TEST.SAS.PROGRAM(SAS1)


So here we are passing the data through PARM statement on SAS.

So inside the SAS program we need to use the SCAN keyword to retrieve the parameter passed from the jcl and modify accordingly.
'Check the SCAN syntax for more details in the manuals'

OPTION SORTLIB='';               
TITLE;                           
                                 
DATA _NULL_;                     
  NAME = SCAN(SYSPARM(),1,','); 
  CALL SYMPUT("TNAME", TNAME);   
  LENGTH FN $50;                
  INFILE INPUTDATA FILENAME=FN;   
  FILE OUTCARD NOPRINT NOTITLES;
....

We can use the Date combination along with the parameter passed to build the output .txt or .csv dynamically.

Friday, June 6, 2014

Output statements using IF ELSE WHEN Clause in SAS - Creating multiple outputs in SAS

Sometimes we need to create multiple outputs in SAS depending on the IF ELSE conditions.The below JCL shows how to achieve this.
//SAS       EXEC SAS                    
//RYAN1     DD DSN=TEST.INPUT.SAS

//SYSOUT    DD SYSOUT=*                     
//SYSIN     DD *                

OPTION NOCENTER;                            
DATA DATA1;                                 
  INFILE RYAN1 MISSOVER;                    
  INPUT @6    POLNO     $CHAR10.            
        @10   CODE      $CHAR04.            
        ;                                   
  DATA EX1 EX2;                             
  SET DATA1;                                
  IF CODE='3992' THEN OUTPUT EX1;        
  IF CODE='T100' THEN OUTPUT EX2;       
  PROC PRINT DATA=EX1;                      
    TITLE 'EX1';                            
  PROC PRINT DATA=EX2;                      
    TITLE 'EX2'; 

Points to note: Both the output datasets, which we want to create should be mentioned in the DATA step. Here EX1 and EX2 are the ones.
Now, we can directly route these outputs to the output datasets as well.

Just a try with SELECT  WHEN clause in SAS  to get the same result.
OPTION NOCENTER;                 
DATA DATA1;                      
  INFILE RYAN1 MISSOVER;          
  INPUT @6    POLNO     $CHAR10. 
        @10   CODE   $CHAR04. 
        ;                        
  DATA EX1 EX2 EX3;              
  SET DATA1;                     
   SELECT (CODE);             
       WHEN  ('3992')  OUTPUT EX1;
       WHEN  ('1002')  OUTPUT EX2;
       OTHERWISE OUTPUT EX3;     
   END;                          
  PROC PRINT DATA=EX1;           
    TITLE 'EX1';                 
  PROC PRINT DATA=EX2;           
    TITLE 'EX2';                 

Saturday, May 3, 2014

SAS in Mainframes(z/Os) Tutorial : Use of symbolic parameter in SAS

Having completed SAS part 1and SAS part 2 , we will see the use of Symbolic in SAS
With the help of symbolic parameters, we can substitute the values dynamically in any place we want to. Say for example we are building the date, or reading the date from one input file and want to use it as a header in title or to use it in any calculation down the flow of the program while doing the condition checks like  <=,>= checks. In these cases the use of symbolic fits the best.
Say like below
DATA DATE;                     
  INFILE DATEIN;               
  INPUT @01  LOWDTE   $CHAR08.  
        @01  HEADER   $CHAR06.  
        @10  HIGHDTE   $CHAR08.  
        ;                      
  PUT "L-DATE >>>>>>>> " LOWDTE;
  PUT "H-DATE >>>>>>>> " HIGHDTE;
                               
   CALL SYMPUT('HEADR',HEADR); 

........
DATA PROCESS1;
 ...
TITLE ' test Heading' "&HEADR" ;
Here.. we are reading the input file, for the Dates and assigning the variables in INFILE DATEIN.
After that there may be several processes occurring in the program.Once done we now want to print the title taking the date read above in INFILE step.  The SYMPUT parameter is used for invoking symbolic parameter in sas. Later down the line we use  &variable-name as used in JCL for the value substitution.
Now ,lets see how we can use this value in sas comprison .
DATA DATA1;  
INFILE IMFL08;
RETAIN CUDATE;   <= Need to declare this variable as RETAIN
INPUT          

  @01   ANO $CHAR 01
  @02   BNO $CHAR02.
.........
CUDATE = "&RUNDATE"; <<== We are assigning the symbolics here
IF EFFDATE LE CUDATE <<= Use symbolic paramter in condition check
    THEN OUTPUT;    

Thursday, March 27, 2014

SAS in Mainframes(z/Os) Tutorial with xamples - Part 2 ( Creating csv/excel file from mainframe dataset using SAS)

1. We will see how we can Merge two or more  input files in SAS and routing it to one output dataset and USE the same dataset to prepare a report in excel format
Creating .xls file on Z/os
(Refer to  Previous  posts to know basic steps in sas)
Lets take two input file, RXX.TEST.FILE3 and RXX.TEST.FILE4 with the fields
CITY,DATE,STATE,AMT in FILE3 and CITY,DATE,STATE,BANK in FILE4.We want to merge both the files so that the output contains CITY DATE STATE BANK.For achieving this, we need have atleast one common field in both the files based on which we can join these two datasets. We will be joining based on CITY.So the steps should be as follows.
Step1.Create the SAS dataset from input file 3 and SORT it on the key field
Step2.Create the SAS dataset from input file 4 and SORT it on the key field
Step3.create a new SAS dataset Using  the MERGE keyword in SAS along with the key field and finally
Step4. take the fields which we need

//SAS01     EXEC SAS                                
//POLIN    DD DSN=RXX.TEST.FILE3,DISP=SHR

//POLIN2   DD DSN=RXX.TEST.FILE4,DISP=SHR
//OUTFILE   DD DSN=RXX.TEST.FILEOUT,DISP=(,CATLG),
//             SPACE=(TRK,(20,20),RLSE),LRECL=180,RECFM=FB
//WORK      DD SPACE=(CYL,(50,10),RLSE)                   
//SYSIN     DD *   

OPTION NOCENTER;                   
OPTION SORTLIB='';                 
  DATA POLIN;                      
   INFILE POLIN;                   
   INPUT @01 CITY   $CHAR02.       
         @06 DATE   $CHAR08.       
         @14 STATE  $CHAR02.       
         @16 AMT    COMMA9.2;      
   PROC SORT DATA=POLIN NODUPS;    
     BY CITY;                                                          
  DATA POLIN2;                     
   INFILE POLIN2;                  
   INPUT @01 CITY   $CHAR02.       
         @06 DATE   $CHAR08.       
         @14 STATE  $CHAR02.       
         @16 AMT    COMMA9.2       
         @25 BANK   $CHAR5;        
                                   
   PROC SORT DATA=POLIN2 NODUPS;   
     BY CITY;                      
  DATA COMMON;                     
  MERGE POLIN(IN=D1) POLIN2(IN=D2);
  BY CITY;                         
  IF D1 AND D2 THEN OUTPUT;        
  PROC PRINT DATA=COMMON;          
     VAR CITY DATE STATE BANK;     
 RUN;                              
 DATA _NULL_;                           
    SET COMMON;                         
    FILE OUTFILE;                       
    PUT CITY ',' DATE ',' STATE ',' BANK;
RUN;                                    
Here goes the output for the same:
***********************
CA ,20130320 ,WB ,BANK1
CA ,20130120 ,TN ,BANK6
CA ,20130120 ,TN ,BANK6
CA ,20130320 ,KA ,BANK6
MI ,20130120 ,KA ,BANK1
MI ,20130320 ,AP ,BANK1
RR ,20130120 ,AP ,BANK8
************************

Why Do we use DATA _NULL_ in SAS ?  This simply is used when we want to make a report.
_NULL_  is a SAS keyword which does not create any SAS dataset.

2. Creating the excel report / CSV file from the mainframe dataset.
To add column headings in SAS to be used in excel sheet, we can use the DATA _NULL_ statement as well.
FILE OUTFILE  DLM=',';
IF _N_=1 THEN DO;
 PUT     'CITY,' 
         'DATE,'
         'STATE,' 
         'BANK'

;
END;

PUT  CITY 
     DATE
     STATE
     BANK
;

To Create a CSV File from a mainframe Dataset we can use the same above code with The delimiter option. DLM=','.(Imp point to remember. Delimeter is the key in creating .xls file)
 (If you remember we need to use delimited option in excel to prepare a formatted report from notepad. DLM option in SAS takes care of that ).
The line of code _N_=1 has special significance. We will check it later. However you can try running the program without using the specific line and see what happens.:)
So we  can download the dataset from command shell (option 6) in ISPF and use 'Receive from Host' option. Save the File in .csv format.
Or otherwise  put one FTP step (where u want to put the report) after the mainframe DATASET is created and save the file in filename_youwant.csv. No need to create a text file and convert it into excel sheet. The FTP location will contain the .xls file and ready to use!!

Sunday, March 23, 2014

SAS in Mainframes(z/Os) Tutorial with xamples - Part 2

We have seen how the data step and Proc functions in the Part 1 of this SAS  blog. We need to remember that the sas datasets or variables created in One Data steps remains defined only to that step unless we specify some condition, using which we can refer to the SAS dataset created in prior steps.In the example below,we are creating the sas Dataset RYAN in the first step.The input file being used in POLIN. Using the statement  'PROC PRINT DATA=RYAN; '  we are printing the output in spool.
Using SET keyword in SAS,in DATA RYAN2 we are referring to the dataset created in the first step and printing the same data in step RYAN2;  SET is the keyword in SAS.
  DATA RYAN;                              
   INFILE POLIN;                           
   INPUT @01 CITY   $CHAR02.

         @06 DATE   $CHAR08.
         @14 STATE  $CHAR02.
         @16 AMT    COMMA9.2;
   PROC SORT DATA=RYAN NODUPS;            
     BY CITY;                     
   PROC PRINT DATA=RYAN;      

                                     
   DATA RYAN2;                            
   SET RYAN; /* this is referring to the dataset created  above*/

   TITLE "I AM SHOWING SAME DATA OF RYAN";
   PROC PRINT DATA=RYAN2;                 
 RUN;                                      
//*

Output:
Obs    CITY      DATE      STATE       AMT   
 1      CA     20130320     WB      100000.55
 2      CA     20130320     WB      200000.55
 3      CA     20130120     TN      500000.55
 4      CA     20130320     KA      600000.55
 5      MI     20130120     KA      300000.55
 6      MI     20130320     AP      400000.55
 7      RR     20130120     AP      700000.55
 8      ST     20130320     TN      800000.55


I AM SHOWING SAME DATA OF POLIN             
Obs    CITY      DATE      STATE       AMT  
 1      CA     20130320     WB      100000.55
 2      CA     20130320     WB      200000.55
 3      CA     20130120     TN      500000.55
 4      CA     20130320     KA      600000.55
 5      MI     20130120     KA      300000.55
 6      MI     20130320     AP      400000.55
 7      RR     20130120     AP      700000.55
 8      ST     20130320     TN      800000.55


Continuing from the program above, we can add more datasets or add more data and carry on with creating the reports.

Friday, March 21, 2014

SAS in Mainframes(z/Os) Tutorial with xamples

To know the SAS Basics, check  Chapter 1  . It demonstrates the very basic working principle of sas.
With your understanding of  the basics in sas, we will start the SAS in mainframe (Z/OS) environment .
The very first thing to know:  Turning Raw Data Into Information is what SAS is all about !!!!

This is the basic principle of how SAS works. The raw data(input file in JCL) is read into SAS through INFILE keyword.This has the same name as the DD name in the JCL.
Once the file is read, the next step is to structure/format the data in SAS Dataset through INPUT keyword as explained below.
 
DATA RYAN;
  INFILE POLIN ;
  INPUT @10  FNAME    $CHAR10.
              @24  ACCTNO   $CHAR05;


Here the keyword DATA  implies the starting of DATA step. RYAN is the name of the Data step.It can be any name.
INFILE POLIN; This is where the raw data is read by sas. POLIN is the JCL DD name for the input.
INPUT @ FNAME $CHAR10...; These statements structures the input dataset read above(here POLIN) and creates a dataset which is internal to SAS(commonly called the SAS data set). Internally SAS would be using this data structure created.
So here the SAS dataset contains FNAME (10 bytes) which is @ 10th position in input file and ACCTNO(5 bytes) which is @ 24th position in input.It wont consider the other records which might be present in the input dataset.
After that we manipulate the data as per our needs and do various functions.In all SAS programs only two steps are of utmost importance namely the DATA step and PROC step.

SAS Syntax Rules:  (A few very handy rules to make life simple!)Can begin and end in any column.
One or more blanks or special characters can be used to separate words.
A single statement can span multiple lines.
Several statements can be on the same line.
/* to begin a comment and */ to end it
 A SAS program generally Mostly comes with the default installation of Z/OS just like DFSORT.Only u need to know the library.
Lets start with few of the basic inbuilt functions and see the output in spool.No input file is required here.Lets see the DATE Function in SAS
//X15122RY  JOB (10,&SYSUID),'RYAN',CLASS=T,

//    MSGCLASS=V,NOTIFY=&SYSUID
//*                                   
//SAS01     EXEC SAS
//WORK      DD SPACE=(CYL,(50,10),RLSE)
//SYSIN     DD *                                            
OPTION NOCENTER;                                                  
OPTION SORTLIB='';
  DATA RYAN;       
    THISYEAR = YEAR(TODAY());           
    THISMONTH= MONTH(TODAY());          
    THISDAY  = DAY(TODAY());            
    LASTYEAR = YEAR(TODAY()) - 1;       
    DATE = TRIM(LEFT(THISYEAR))|| '1101';
  PROC PRINT DATA= RYAN;
   VAR THISYEAR LASTYEAR THISMONTH DATE THISDAY
//*

Output:
The SAS  System
Obs    THISYEAR    LASTYEAR    THISMONTH      DATE      THISDAY
 1       2013        2012          6        20131101       20   

Looks Cool!
Now , as we can see the value of  THISMONTH is 6. What if we want to get and display like 06
So we need to modify the date function output to get two digits output .
THISMONTH= PUT(MONTH(TODAY()),Z2.);
HDR = TRIM(LEFT(THISYEAR))|| PUT(LASTMONTH,Z2.);
Explanation:
Option NOCENTER; is SAS statement which aligns the output. Lets not be bothered about that.
We can see the data step starts with DATA RYAN;
Since no input file is used here, so we do not have infile and input statements here.
Today() is a function in SAS. It can be used with various combinations to give us the dates we want.
PROC PRINT DATA=RYAN is the proc step. We are using the keyword VAR to include or select the variables from  the data step to print.

Lets go to the Next step will be to add an input file and print its contents.
//SAS01     EXEC SAS
//POLIN    DD DSN=I15122.TEST.FILE,DISP=SHR <== input dataset
//WORK      DD SPACE=(CYL,(50,10),RLSE)
//SYSIN     DD *                                            
OPTION NOCENTER;                                                  
OPTION SORTLIB='';

DATA RYAN;       
  INFILE POLIN;
  INPUT @01 CITY   $CHAR02.
        @06 DATE   $CHAR08.
        @14 STATE  $CHAR02.
        @16 AMT    COMMA9.2;
  PROC PRINT DATA= RYAN;

This is how the input looks like.
Input File:
----+----1----+----2----+-
**************************
CA00020130320WB100000.55 
CA00020130320WB200000.55 
MI00020130120KA300000.55 
MI00020130320AP400000.55 
CA00020130120TN500000.55 
CA00020130320KA600000.55 
RR00020130120AP700000.55 
ST00020130320TN800000.55 
**************************

Output:
The SAS System
Obs    CITY      DATE      STATE       AMT  
 1      CA     20130320     WB      100000.55
 2      CA     20130320     WB      200000.55
 3      MI     20130120     KA      300000.55
 4      MI     20130320     AP      400000.55
 5      CA     20130120     TN      500000.55
 6      CA     20130320     KA      600000.55
 7      RR     20130120     AP      700000.55
 8      ST     20130320     TN      800000.55


The fist column is inserted by SAS in the output called observation column,ie number of rows processed.Use of NOOBS in the proc statement will suppress the First column.
If we would run it with NODUPKEYS with Key on the CITY, then it would remove all the duplicate key values.The below code shows how PROC SORT can be used to sort out the data and filter out duplicate.. We need to give one key value if we use NODUPKEYS. If we do not give we will get the below error.
ERROR: No BY statement used or no BY variables specified. A BY statement must be used with variable names to sort on.
DATA RYAN;       
  INFILE POLIN;
  INPUT @01 CITY   $CHAR02.
        @06 DATE   $CHAR08.
        @14 STATE  $CHAR02.
        @16 AMT    COMMA9.2;
  PROC SORT DATA= RYAN NODUPKEYS;

       BY CITY;
     PROC PRINT DATA= RYAN
Output:
Obs    CITY      DATE      STATE       AMT
 1      CA     20130320     WB      100000.55
 2      MI     20130120     KA      300000.55
 3      RR     20130120     AP      700000.55
 4      ST     20130320     TN      800000.55

How ever we can also use NODUPS; This will check the entire observation and filter out only if entire observation is duplicate.

Limiting the number of observations in SAS
Suppose You have a input of million records , but you want to proceed or test your code with 10 records. In this scenario, it is advisable to use OBS=number-of-records  along with the infile statement. This will restrict the number of records to 10
DATA RYAN;       
  INFILE POLIN OBS=10 ;
....

Using a simple IF loop and THEN OUTPUT in SAS
lets add the below line before we print the SAS data using PROC PRINT.
IF(( CITY NE 'RR') OR (CITY='SS')) THEN OUTPUT;
PROC PRINT DATA=RYAN;

It wil print all the records except the observation with city value of RR.

Next,Lets do some more modifications to make the output dataset more meaningful:
Say, we want to add one more column which will tell us the city name in full, ie for the observation where the CITY is MI, it should say MICHIGAN.
 So we need to add one more variable which will be added in the output. 
INFILE POLIN;
  INPUT @01 CITY   $CHAR02.
        @06 DATE   $CHAR08.
        @14 STATE  $CHAR02.
        @16 AMT    COMMA9.2;

LENGTH CITY_NAME $20;
IF CITY = 'RR' THEN CITY_NAME ='ROCK VINE' ;
ELSE                                        
IF CITY = 'MI' THEN CITY_NAME ='MICHIGAN' ; 
ELSE                                        
IF CITY = 'CA' THEN CITY_NAME ='CALIFORNIA'; 

     PROC PRINT DATA= RYAN;
       VAR CITY DATE STATE AMT CITY_NAME; 
Here goes the output:

CITY      DATE      STATE       AMT       CITY_NAME
 CA     20130320     WB      100000.55    CALIFORNI
 CA     20130320     WB      200000.55    CALIFORNI
 MI     20130120     KA      300000.55    MICHIGAN 
 MI     20130320     AP      400000.55    MICHIGAN 
 CA     20130120     TN      500000.55    CALIFORNI
 CA     20130320     KA      600000.55    CALIFORNI
 RR     20130120     AP      700000.55    ROCK VINE
 ST     20130320     TN      800000.55             


Why did we add the line LENGTH CITY_NAME $20; ???. Ideally our job would have run without that part also, but the City name would have been truncated. Using that line we are making sure it takes 20 bytes and no truncation happens.!
To be continued.....  SAS in Mainframes(z/Os)  - Part 2  !! drop a note if u liked it.