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"
*/
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.