Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created November 10, 2023 21:28
Show Gist options
  • Select an option

  • Save statgeek/c88586561ba3d120844c350f4ef3145c to your computer and use it in GitHub Desktop.

Select an option

Save statgeek/c88586561ba3d120844c350f4ef3145c to your computer and use it in GitHub Desktop.

Revisions

  1. statgeek created this gist Nov 10, 2023.
    28 changes: 28 additions & 0 deletions SAS_unzip_copy_extract_xpt.sas
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    *path to the zip file;
    filename src zip "/home/fkhurshed/Demo2/P_DR2IFF.zip";

    *path to where to save the xpt file;
    filename xl "/home/fkhurshed/Demo2/P_DR2IFF.xpt" ;

    *extract file from zip - P_DR2IFF.XPT in the code below is the name of the file in the zipped file that is to be extracted;
    data _null_;
    /* using member syntax here */
    infile src(P_DR2IFF.XPT)
    lrecl=256 recfm=F length=length eof=eof unbuf;
    file xl lrecl=256 recfm=N;
    input;
    put _infile_ $varying256. length;
    return;
    eof:
    stop;
    run;

    *where to store the SAS dataset;
    libname projfile '/home/fkhurshed/Demo2/';

    *XPT file (same as filename xl as above);
    libname xptfile xport '/home/fkhurshed/Demo2/P_DR2IFF.xpt' access=readonly;

    *extract the SAS dataset from the XPT file;
    proc copy inlib=xptfile outlib=projfile;
    run;