Add-Innovation Home

About Add-Innovation

Contact Us

  SAS Institute logo.   Use data views to save space.

Data views allow a definition of an external file to be created, allowing that file to be processed as if it was a SAS dataset. This allows two external files which are sorted in the same logical order to be merged without first reading them into SAS datasets and hence saving large amounts of space. The use of views may be “stacked” together, so a view may be defined as the merge of two other views. For example, if the Orders Master file and Inventory file are to be merged together by Installation Id, the files must first be processed to remove the duplicate records. This is much simpler, and saves much more space using Data Views ;

Data Orders(Keep=Prodcode InstId OLADate) / View=Orders;
    Length OLADate 4;
    Infile Orders;
    Input @109 Prodcode $6.@;
    If Prodcode In (‘A12345’,’A12346’,’A12347’);
    Input @91 OLA $1.@;
    If OLA=’P’;
    Input @1 InstId $12.
      @92 OLADate 8.;

Data     Invent / View=Invent;
    Infile Invent;
    Input @15 Prodcode $6.@;
    If Prodcode In (‘A12345’,’A12346’,’A12347’);
    Input @1 InstId $12.

Data Order2 / View=Order2;
    Set Orders;
    By InstId;
    Retain A5 A6 A7 ‘ ‘;
    If First.InstId Then Do;
        A5=’ ‘;
        A6=’ ‘;
        A7=’ ‘;
    End;
    If Prodcode = ‘A12345’ Then A5=’Y’;
Else If Prodcode = ’A12346’ Then A6=’Y’;
Else If Prodcode = ’A12347’ Then A7=’Y’;
If Last.InstId and A5=’Y’ and A6=’Y’ and A7=’Y’;

Data Invent2 / View=Invent2;
    Set Invent;
    By InstId;
    Retain A5 A6 A7 ‘ ‘;
    If First.InstId Then Do;
        A5=’ ‘;
        A6=’ ‘;
        A7=’ ‘;
    End;
    If Prodcode = ‘A12345’ Then A5=’Y’;
Else If Prodcode = ’A12346’ Then A6=’Y’;
Else If Prodcode = ’A12347’ Then A7=’Y’;
If Last.InstId and A5=’Y’ and A6=’Y’ and A7=’Y’;

Data Both / View=Both;
    Merge Order2(In=INOrder)
        Invent2(In=InInvent);
    By InstId;
    If InOrder and InInvent;

Proc Sort Data=Both Out=Sorted NoEquals;
    By OLADate;

In the above example no data is copied to working storage until the sort is executed.