-
Notifications
You must be signed in to change notification settings - Fork 8
/
ext.sas
72 lines (54 loc) · 2.36 KB
/
ext.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%macro Ext(file,name,case=UP) / des='Output the extension for a file';
/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: Ext
Author: Chris Swenson
Created: 2011-02-09
Purpose: Output the extension for a specified file, either as a direct
output or as a macro variable.
Arguments: file - filename to output extension for
name - name of macro variable to output
case - up (default) or low for the output case
Examples: %if %ext(c:\test\text.txt)=txt %then %do; ... %end;
%ext(c:\test\text.txt, ext);
%if &EXT=TXT %then %do; ... %end;
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/
%let case=%upcase(&CASE);
/* Check for a blank file argument */
%if %superq(FILE)=%str() %then %do;
%put %str(E)RROR: No argument specified for FILE.;
%return;
%end;
%if %index(*LOW*LOWCASE*UP*UPCASE*,*&CASE*)=0 %then %do;
%put %str(E)RROR: %str(I)nvalid argument specified for CASE. Please use UP or LOW.;
%return;
%end;
/* Find extension */
%local _ext_;
%let _ext_=%scan(%superq(FILE), -1, %str(.));
/* Set case */
%if %index(*UP*UPCASE*,*&CASE*)>0 %then %do;
%let _ext_=%upcase(&_EXT_);
%end;
%else %if %index(*LOW*LOWCASE*,*&CASE*)>0 %then %do;
%let _ext_=%lowcase(&_EXT_);
%end;
/* Output extension if no macro variable name specified */
%if %superq(NAME)=%str() %then %do;
&_EXT_
%end;
/* Output extension as macro variable */
%else %do;
%global &NAME;
%let &NAME=&_EXT_;
%put NOTE: The extension is &_EXT_ (macro variable %upcase(&NAME)).;
%end;
%mend Ext;