-
Notifications
You must be signed in to change notification settings - Fork 8
/
xpttype.sas
55 lines (50 loc) · 1.96 KB
/
xpttype.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%macro xpttype(filename /* fileref or quoted physical filename */);
/*----------------------------------------------------------------------------
Check file to see what type of transport file it is.
Returns
CPORT for PROC CPORT/CIMPORT file
XPORT for V5 export file
XPORT_V9 for V8/9 export file
SAS7BDAT for SAS dataset
UNKNOWN for any other file
Examples:
%put %xpttype('~/xport.xpt');
%put %xpttype('~/subj.xpt');
%put %xpttype('~/r_lrevw.xpt');
%put %xpttype('~/test1.sas7bdat');
----------------------------------------------------------------------------*/
%local return rc ;
%*----------------------------------------------------------------------------
Set default value of UNKNOWN
-----------------------------------------------------------------------------;
%let return=UNKNOWN;
%*----------------------------------------------------------------------------
Use %SYSFUNC() to call DOSUBL to run a data step to read the first 80 bytes
of the file.
-----------------------------------------------------------------------------;
%let rc=%sysfunc(dosubl(%nrstr(
data _null_;
infile &filename recfm=f lrecl=80 obs=1;
input;
list;
if _infile_=
'**COMPRESSED** **COMPRESSED** **COMPRESSED** **COMPRESSED** **COMPRESSED********'
then call symputx("return",'CPORT');
else if _infile_=:'HEADER RECORD*******LIB'
and substr(_infile_,29)='HEADER RECORD!!!!!!!000000000000000000000000000000' then do;
select (substr(_infile_,21,8));
when ('LIBRARY') call symputx("return",'XPORT');
when ('LIBV8') call symputx("return",'XPORT_V9');
otherwise;
end;
end;
else if _infile_=:'000000000000000000000000c2ea8160b31411cfbd92080009c7318c181f1011'x
then call symputx("return",'SAS7BDAT')
;
run;
)));
%*----------------------------------------------------------------------------
Return to value of &RETURN as the output of the macro.
-----------------------------------------------------------------------------;
&return.
%mend xpttype ;