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"
*/
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: