So the problem with your first XPT file is that HAVEN put binary zeros into the FORMAT and INFORMAT name fields on the V8 NAME records instead of spaces.
You can fix the XPT2LOC macro to read that file if you just add in code to convert the binary zeros to spaces after they are read.
...
format = input(substr(buffer,pos, 8),$ascii8.); pos+8;
...
informat = input(substr(buffer,pos, 8),$ascii8.); pos+8;
...
format=translate(format,' ','00'x);
informat=translate(informat,' ','00'x);
Another issue I have seen is someone sent a file that had bare $ as the FORMAT or INFORMAT specification in the V9 LABEL record. For those I just blanked them out.
...
format=substr(buffer,name_len+label_len+1,fmtname_len);
informat=substr(buffer,name_len+label_len+fmtname_len+1,infmtname_len);
if format='$' then do;
putlog 'WARNING: Removing invalid ' format=:$quote. 'from variable ' name;
format=' ';
end;
if informat='$' then do;
putlog 'WARNING: Removing invalid ' informat=:$quote. 'from variable ' name;
informat=' ';
end;
If your R software and SAS software reside on the same machine (server/desktop/laptop), then this paper Using the R interface in SAS ® to Call R Functions and Transfer Data might provide you with an alternative to your current export approach.
Hope this helps,
Ahmed
Perhaps instead of writing XPT from R a simple CSV file? If the file is of the same structure a data step would read that easily if people aren't understanding how XPT files are to be used.
IIRC the XPT file format came about when SAS supporting a much larger number of computer operating systems that basically did not talk to each other much and predates the desktop PC versions. So it was expected that a little bit of code to run on the receiving end was acceptable, not just "click and use" a file.(Predates mouse clicks for most OS as well).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.