You can ask windows kernel via modulen. Packaging it neatly into a user-written function (or a macro) is left as an exercise for the interested reader(s). 🙂
/* cd to work */
%let pwd = %sysfunc(pathname(work));
%put pwd=&pwd;
x cd &pwd;
/* create a test file with a long name */
%let long = long file name.txt;
options noxwait;
x "copy nul ""&long""";
/* create sascbtbl */
filename sascbtbl catalog "work.winapi.fm.source";
data _null_;
file sascbtbl; input; put _infile_;
cards4;
routine GetShortPathNameA module=KERNEL32 minarg=3 maxarg=3 stackpop=called returns=long;
arg 1 input char format=$cstr256.;
arg 2 output char format=$cstr256.;
arg 3 input num format=pib4.;
;;;;
run;
/* call the win32 api func via modulen */
data _null_;
length long short $256;
long = "&long" || byte(0);
short = byte(0);
rc = modulen("*e", "GetShortPathNameA", long, short, 0);
short = scan(short, 1, byte(0));
if rc=0 then
put "Uh-oh!";
else
put (long short) (= :quote.);
run;
filename sascbtbl clear;
/* on log
long="long file name.txt " short="LONGFI~1.TXT"
*/
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.