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.

1 comment: