Discussion:
AN URGENT - XPT TO SAS DATASET WITH MACRO - MORE DETAIL
(too old to reply)
Rathindronath
2006-06-28 18:38:05 UTC
Permalink
I am using this following program to convert xpt files to SAS datasets.


libname Tmp1 xport 'd:\3074P308\aacu.xpt';
libname xptfile 'C:\xptfol';
proc copy in=Tmp1 out=xptfile;
run;



But I have too many datasets. so I need a simple macro which can read all
the dataset and convert them all at the same time.
Thanks
Venky Chakravarthy
2006-06-28 19:26:08 UTC
Permalink
Post by Rathindronath
I am using this following program to convert xpt files to SAS datasets.
libname Tmp1 xport 'd:\3074P308\aacu.xpt';
libname xptfile 'C:\xptfol';
proc copy in=Tmp1 out=xptfile;
run;
But I have too many datasets. so I need a simple macro which can read all
the dataset and convert them all at the same time.
Thanks
It looks like you are on a Windows platform. I think you can use a wild
card to facilitate the reading of multiple xpt files. This can be done
without a macro. Try this:

filename getxpt pipe "dir 'd:\3074P308\*.xpt" ;
libname xptfile 'C:\xptfol';

data _null_ ;
length fname $30 ;
infile getxpt ;
input ;
fname = scan(_infile_,-1," ") ;
if scan(fname,-1,".") = "xpt" ;
call execute (
"libname Tmp1 XPORT '\\client\c$\junk\"||trim(fname)||"';" ||
" proc copy in = Tmp1 out = out=xptfile ; run ; " ) ;
run ;

Venky Chakravarthy
Venky Chakravarthy
2006-06-28 20:20:13 UTC
Permalink
FIRST specify the correct path. I had mine in there and you have run the
code as is. In case it is not obvious

change
13 "libname Tmp1 XPORT '\\client\c$\junk\"||trim(fname)||"';" ||
to

"libname Tmp1 XPORT 'd:\3074P308\"||trim(fname)||"';" ||

Venky Chakravarthy
NOTE: Copyright (c) 2002-2003 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) 9.1 (TS1M3)
Licensed to WYETH, Site 0011279001.
NOTE: This session is executing on the WIN_PRO platform.
real time 9.56 seconds
cpu time 0.54 seconds
ERROR: Expecting page 1, got page -1 instead.
ERROR: Page validation error while reading SASUSER.PROFILE.CATALOG.
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
1 proc copy in=TMP1 out=WORK;
2 run;
NOTE: Input library TMP1 is sequential.
NOTE: Copying TMP1.AACULT to WORK.AACULT (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
System Option for BUFSIZE was used.
NOTE: There were 6591 observations read from the data set TMP1.AACULT.
NOTE: The data set WORK.AACULT has 6591 observations and 51 variables.
real time 3.26 seconds
cpu time 0.11 seconds
3 filename getxpt pipe "dir 'd:\3074P308\*.xpt" ;
4 libname xptfile 'C:\xptfol';
Engine: V9
Physical Name: C:\xptfol
5
6 data _null_ ;
7 length fname $30 ;
8 infile getxpt ;
9 input ;
10 fname = scan(_infile_,-1," ") ;
11 if scan(fname,-1,".") = "xpt" ;
12 call execute (
13 "libname Tmp1 XPORT '\\client\c$\junk\"||trim(fname)||"';" ||
14 " proc copy in = Tmp1 out = out=xptfile ; run ; " ) ;
15 run ;
Unnamed Pipe Access Device,
PROCESS=dir 'd:\3074P308\*.xpt,RECFM=V,
LRECL=256
The filename, directory name, or volume label syntax is incorrect.
NOTE: 0 records were read from the infile GETXPT.
real time 0.29 seconds
cpu time 0.01 seconds
Rathindronath
2006-06-28 20:11:14 UTC
Permalink
RUNNING YOUR CODE i GOT THIS ERROR:

NOTE: Copyright (c) 2002-2003 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) 9.1 (TS1M3)
Licensed to WYETH, Site 0011279001.
NOTE: This session is executing on the WIN_PRO platform.


NOTE: SAS initialization used:
real time 9.56 seconds
cpu time 0.54 seconds
ERROR: Expecting page 1, got page -1 instead.
ERROR: Page validation error while reading SASUSER.PROFILE.CATALOG.
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
1 proc copy in=TMP1 out=WORK;
2 run;
NOTE: Input library TMP1 is sequential.
NOTE: Copying TMP1.AACULT to WORK.AACULT (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
System Option for BUFSIZE was used.
NOTE: There were 6591 observations read from the data set TMP1.AACULT.
NOTE: The data set WORK.AACULT has 6591 observations and 51 variables.
NOTE: PROCEDURE COPY used (Total process time):
real time 3.26 seconds
cpu time 0.11 seconds

3 filename getxpt pipe "dir 'd:\3074P308\*.xpt" ;
4 libname xptfile 'C:\xptfol';
NOTE: Libref XPTFILE was successfully assigned as follows:
Engine: V9
Physical Name: C:\xptfol
5
6 data _null_ ;
7 length fname $30 ;
8 infile getxpt ;
9 input ;
10 fname = scan(_infile_,-1," ") ;
11 if scan(fname,-1,".") = "xpt" ;
12 call execute (
13 "libname Tmp1 XPORT '\\client\c$\junk\"||trim(fname)||"';" ||
14 " proc copy in = Tmp1 out = out=xptfile ; run ; " ) ;
15 run ;
NOTE: The infile GETXPT is:
Unnamed Pipe Access Device,
PROCESS=dir 'd:\3074P308\*.xpt,RECFM=V,
LRECL=256
Stderr output:
The filename, directory name, or volume label syntax is incorrect.
NOTE: 0 records were read from the infile GETXPT.
NOTE: DATA statement used (Total process time):
real time 0.29 seconds
cpu time 0.01 seconds
Nordlund, Dan (DSHS)
2006-06-28 21:08:09 UTC
Permalink
-----Original Message-----
Rathindronath
Sent: Wednesday, June 28, 2006 1:11 PM
Subject: Re: AN URGENT - XPT TO SAS DATASET WITH MACRO - MORE DETAIL
NOTE: Copyright (c) 2002-2003 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) 9.1 (TS1M3)
Licensed to WYETH, Site 0011279001.
NOTE: This session is executing on the WIN_PRO platform.
real time 9.56 seconds
cpu time 0.54 seconds
ERROR: Expecting page 1, got page -1 instead.
ERROR: Page validation error while reading SASUSER.PROFILE.CATALOG.
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
1 proc copy in=TMP1 out=WORK;
2 run;
NOTE: Input library TMP1 is sequential.
NOTE: Copying TMP1.AACULT to WORK.AACULT (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
System Option for BUFSIZE was used.
NOTE: There were 6591 observations read from the data set TMP1.AACULT.
NOTE: The data set WORK.AACULT has 6591 observations and 51 variables.
real time 3.26 seconds
cpu time 0.11 seconds
3 filename getxpt pipe "dir 'd:\3074P308\*.xpt" ;
4 libname xptfile 'C:\xptfol';
Engine: V9
Physical Name: C:\xptfol
5
6 data _null_ ;
7 length fname $30 ;
8 infile getxpt ;
9 input ;
10 fname = scan(_infile_,-1," ") ;
11 if scan(fname,-1,".") = "xpt" ;
12 call execute (
13 "libname Tmp1 XPORT '\\client\c$\junk\"||trim(fname)||"';" ||
14 " proc copy in = Tmp1 out = out=xptfile ; run ; " ) ;
15 run ;
Unnamed Pipe Access Device,
PROCESS=dir 'd:\3074P308\*.xpt,RECFM=V,
LRECL=256
The filename, directory name, or volume label syntax is incorrect.
NOTE: 0 records were read from the infile GETXPT.
real time 0.29 seconds
cpu time 0.01 seconds
I see that Venky has pointed out your use of an incorrect pathname. There
also seems to be an extraneous single quote in your filename statement. In
addition this can be simplified slightly.

**--using /b parameter will simplify the directory listing--**;
filename getxpt pipe "dir /b d:\3074P308\*.xpt" ;
libname xptfile 'C:\xptfol';

data _null_ ;
length fname $30 ;
infile getxpt ;

**--because of /b above, no need to clean up filenames--**;
**-- just read in filename--**;
input fname;

call execute (
"libname Tmp1 XPORT 'd:\3074P308\"||trim(fname)||"';" ||
" proc copy in = Tmp1 out = out=xptfile ; run ; " ) ;
run ;

Hope this is helpful,

Dan

Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services
Olympia, WA 98504-5204

Loading...