BookmarkSubscribeRSS Feed
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Mmm, its odd that the wildcard doesn't work.  Anyways, just change to:

%macro imp_xml (fname=,mapname=);

  /* This is your original code, I have just replaced the file and map name as parameters */
  filename datafile 'h:\Practice\PARI\&fname.';
  filename mapfile 'h:\Practice\PARI\XML\&mapname.';
  libname datafile xmlv2 xmlmap=mapfile automap=replace;

  proc copy in=datafile out=work; 
  run;
  
  filename datafile clear;
  filename mapfile clear;
  libname datafile clear;

%mend imp_xml;
 
/* Clean work so that we can append all datasets created */
proc datasets lib=work memtype=data kill nolist;
run;

/* This is a pipe from your Operating system, it is the same as doing a directory listing
   from the command prompt.  It will feedback all the filenames with the extension xml
   in the folder given */
filename inlist pipe 'dir "h:/Practice/PARI" /b';

/* I replace the _null_ part here, you can look at dirlist dataset in work to see what is read
   in from the directory listing */
data dirlist;
  length buff mfile $200;
  infile inlist;
  input buff $;
  mfile=tranwrd(lowcase(buff),".xml",".map");
/* The next step creates one macro call for every filename returned by the directory listing
   from the command prompt */
  call execute(cats('%macro imp_xml (fname=',buff,',
                                     mapname=',mfile,');'));
run;

filename inlist clear;

/* Combine all the datasets in work */
data _null_;
  set sashelp.vtable (where=(libname="WORK"));
/* These next steps will generate firstly one dataset called want, then from there on in
   one proc append for every dataset in the work library */
  if _n_=1 then call execute(cats('data want; set ',strip(memname),';run;'));
  else call execute(cats('proc append base=want append=',strip(memname),' force;run;'));
run;

/* Remove all files except the final one */
proc datasets lib=work memtype=data kill nolist;
  save want;
run;

So just take the /*.xml  

Off the pipe and it should list all the files in that directory.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 15 replies
  • 4269 views
  • 0 likes
  • 2 in conversation