BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sbxkoenk
SAS Super FREQ

Hello @Kurt_Bremser ,

 

I did not know PROC XCOPY either.

It appears in the documentation in examples where they are dealing with the Medical Expenditure Panel Survey (MEPS) data.

 

Like here :
SAS/STAT® 15.2 User's Guide
The SURVEYLOGISTIC Procedure
Example 119.2 The Medical Expenditure Panel Survey (MEPS)
https://go.documentation.sas.com/doc/en/statug/15.2/statug_surveylogistic_examples02.htm

But I cannot find "official" PROC XCOPY doc (the way other procedures are documented). Not on the web and not in the Windows help that comes with my SAS 9.4 M7 localhost installation.

 

Strange indeed!

 

Thanks,

Koen

Banke
Pyrite | Level 9

You are right. I am using it for a MEPS project. They have a macro code for importing directly from their website but it didnt work for me.

Possibly bacuse its quite complicated and i understand it.

 

Please find the link below:

 

https://github.com/HHS-AHRQ/MEPS-workshop/blob/master/sas_exercises/Automate_Load_SAS9_Files.sas 

 

 

Tom
Super User Tom
Super User

So looking quickly at what they have published for H206A

https://meps.ahrq.gov/data_files/pufs/h206a

they have published both a SAS7BAT file and CPORT file, both are published as ZIP files.  I do not see any XPORT file (but I did not download everything).

 

If you want to download the CPORT file (the one with the .ssp extension) then you could use code like this:

%let path= <some path on your SAS machine>;

filename meps url "https://meps.ahrq.gov/data_files/pufs/h206a/h206assp.zip" recfm=f lrecl=512;
filename out "&path/h206assp.zip" recfm=f lrecl=512;
%put rc=%sysfunc(fcopy(meps,out));
filename cport zip "&path/h206assp.zip" member="H206A.ssp" recfm=f lrecl=80;
libname mylib base "&path";

proc cimport infile=cport lib=mylib;
run;

Or you could skip the CPORT file and just download the ZIP file with the SAS7BDAT file in it.  Then instead of PROC CIMPORT you just need to do another copy to get the file out of the ZIP file.

filename in1 url "https://meps.ahrq.gov/data_files/pufs/h206a/h206av9.zip" recfm=f lrecl=512;
filename out1 "&path/h206av9.zip" recfm=f lrecl=512;
%put rc=%sysfunc(fcopy(in1,out1));
filename in2 zip "&path/h206av9.zip" member="h206a.sas7bdat" recfm=f lrecl=512;
filename out2 "&path/h206a.sas7bdat" recfm=f lrecl=512;
%put rc=%sysfunc(fcopy(in2,out2));

Checking the results:

proc contents data=mylib.h206a ;
run;

image.png

Banke
Pyrite | Level 9

Thats really great, better than my code. Thanks

Banke
Pyrite | Level 9

Hello all,

 

Thanks very much for your help.

 

Thank you so much 

@sbxkoenk    @PaigeMiller  @Reeza and @Kurt_Bremser 

 

This worked:

%let path = C:\Users\HP SPECTRE\OneDrive\MEPSProject;
libname MEPS_P "&path.";

%macro imp (MEPFILE);
filename &MEPFILE.  "&path.\RAW\&MEPFILE..ssp";
proc xcopy in = &MEPFILE. out = MEPS_P import;
run;
%mend imp;

%imp (H163);
%imp (H171);
%imp (H181);
%imp (H162);
%imp (H170);
%imp (H180);
%imp (H160a);
%imp (H168a);
%imp (H178a);

  

Tom
Super User Tom
Super User

Note that the XCOPY procedure is pretty ancient.  If you have V5 transport files (which is looks like you do) you can use the XPORT engine with a LIBNAME statement to read from them. For example by using PROC COPY.

libname source xport "&path.\RAW\&MEPFILE..ssp";
libname target base "&path.\SASDATA";
proc copy inlib = source outlib = target ;
run;

If you want to check what type of file you have you can just check the beginning of the file.  SAS transport files (of all types) are binary files so read it using RECFM=F and LRECL=80.

data _null_;
  infile xxx lrecl=80 recfm=f obs=6;
  input;
  list;
run;

Example of a V5 transport file created using XPORT library engine using SAS verison 9.4.

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
1         HEADER RECORD*******LIBRARY HEADER RECORD!!!!!!!000000000000000000000000000000
2         SAS     SAS     SASLIB  9.4     X64_10PR                        20NOV21:12:03:58
3         20NOV21:12:03:58
4         HEADER RECORD*******MEMBER  HEADER RECORD!!!!!!!000000000000000001600000000140
5         HEADER RECORD*******DSCRPTR HEADER RECORD!!!!!!!000000000000000000000000000000
6         SAS     CLASS   SASDATA 9.4     X64_10PR                        20NOV21:12:03:58
Banke
Pyrite | Level 9
Thanks. I've always wondered what lrecl and recfm meant in codes. Undertanding SAS and macros better
PaigeMiller
Diamond | Level 26

@Banke wrote:
Text

Repeating: "How would macros help here?"


What would the macro do?

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 23 replies
  • 4327 views
  • 5 likes
  • 6 in conversation