BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
HitmonTran
Pyrite | Level 9

Hello,

 

I'm using an existing code template to convert sas data to xpt; however, when i run the code i get an error message.  Please help!!!!

 

error message:

HitmonTran_0-1731734660944.png

 

 

sas code:

%macro sas2xpt (sasdir=, xptdir=);

x "cd &sasdir";
filename files pipe "dir /b *.sas7bdat";

data _null_;
   infile files;
   length fname $ 200;
   retain i 0;
   input fname;
   i = i + 1;
   call symput("f"||left(put(i,7.)), trim(left(scan(fname,1,'.'))));
   call symput("fcnt", trim(left(i)));
run;

%put &f1;


libname insas "&sasdir";
%macro dothis;
%do i = 1 %to &fcnt;
libname tranfile xport "&xptdir\&&f&i...xpt";
  proc copy in=insas out=tranfile memtype=data;
   select &&f&i;
  run;
%end;
%mend dothis;
%dothis;

%mend sas2xpt;


**example toc all the macro**;

%sas2xpt(sasdir=%str(\\itsu.com\\Analysis\Working_Folder\ads), xptdir=(\\itsu.com\\Analysis\Working_Folder\ads) );
run;

folder structure:

HitmonTran_1-1731734726770.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

So the issue does not appear to be the conversion to XPORT files. Instead it is the attempt to force WINDOWS to use a UNC path as the current working directory.  That is not possible.  And not needed.

 

There are plenty of ways to get the list of files in a directory.  You can even use pure SAS code.  See %dirtree() 

 

Or you could just make a small change to your current code:

data _null_;
   infile "dir /b &sasdir\*.sas7bdat" pipe truncover;
   input fname $200. ;
   call symputx(cats('f',_n_),scan(fname,1,'.'));
   call symputx("fcnt",_n_);
run;

 

Also you are passing () around the value of the target directory in your macro call, which will cause the wrong filenames to be generated.  Did you intend to wrap that path in a %STR() macro function call also?  Note that the %STR() is not needed for the example paths you are showing since they do not include any macro triggers that need masking.

%sas2xpt
(sasdir=\\itsu.com\Analysis\Working_Folder\ads
,xptdir=\\itsu.com\Analysis\Working_Folder\ads
);

 

View solution in original post

3 REPLIES 3
Ksharp
Super User

The following code is what I wrote for one to one converting to xpt file of V5.

 

libname in v9 'c:\temp\SAS'    access=readonly;   /*the path of sas datasets*/
%let path_out=  c:\temp\XPT   ;                   /*the path of xpt after converting*/

/*one dataset corresponding to one xpt file*/
data _null_;
 set sashelp.vtable(keep=libname memname where=(libname='IN'));
call execute(cat("libname tranfile xport '&path_out\",lowcase(strip(memname)),".xpt';proc copy in=in out=tranfile ; select ",strip(memname),";run;"));
run;

 

 

Patrick
Opal | Level 21

The issue is:

Patrick_0-1731750989816.png

 

You would have to use something like powershell in your pipe command. The default cmd.exe simply doesn't support UNC paths. This is a Microsoft thing and nothing you can change.

But... There is really no need to use an external command which requires XCMD to list files and especially SAS tables. Just use an approach along the line of what @Ksharp already proposed.

 

If you want to use your current code as-is then you need to map this UNC path (=give it a drive letter) on the machine where SAS executes.

Tom
Super User Tom
Super User

So the issue does not appear to be the conversion to XPORT files. Instead it is the attempt to force WINDOWS to use a UNC path as the current working directory.  That is not possible.  And not needed.

 

There are plenty of ways to get the list of files in a directory.  You can even use pure SAS code.  See %dirtree() 

 

Or you could just make a small change to your current code:

data _null_;
   infile "dir /b &sasdir\*.sas7bdat" pipe truncover;
   input fname $200. ;
   call symputx(cats('f',_n_),scan(fname,1,'.'));
   call symputx("fcnt",_n_);
run;

 

Also you are passing () around the value of the target directory in your macro call, which will cause the wrong filenames to be generated.  Did you intend to wrap that path in a %STR() macro function call also?  Note that the %STR() is not needed for the example paths you are showing since they do not include any macro triggers that need masking.

%sas2xpt
(sasdir=\\itsu.com\Analysis\Working_Folder\ads
,xptdir=\\itsu.com\Analysis\Working_Folder\ads
);

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 850 views
  • 2 likes
  • 4 in conversation