BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

 

I have developed using EG 7.13 to convert a SAS data set into an xml file (see the code below).  Moreover, as the data set is too large

the program allow to fragment the xml file into smaller xml file to optimize the process time and facilitate the treatment.

 

I am not familiar at all with ksh file and I am beginning to execute SAS program on Unix server.  Please apologize if my questions seems basic.

 

So I have few parameters I would like to passed to the SAS program in order to permit it to execute properly such as:

 

myReport : refer to the libname where I want the xml file to be written

mywork:  refer to the libname where the SAS data set is located

MyReport1 is a macro variable which indicate the path to location of the xml files.

FileName is a macro variable telling what's the SAS data set Name.

NbObsPerDst is a macro variable which specify how many observations we want in an xml file ex: 250000

=&Gnobs., is the total number of observations into the SAS data set and is estimated by the program. (Global variable)

FNameIn is a macro variable containing the location and the name of the SAS data set (mywork.&FileName)

FNameOut is a macro variable telling what will be the xml file name. ex: FNameOut= test then the xml file name will be:

 

test_1

test_2

.

.

.

test_n

 

So the question is how to specify the above mentioned parameters in the ksh file to make sure that the SAS program will execute properly till the end.

Regards,

 

 

KSH file:

 

#!/bin/sh
echo "1.- Strating my SAS program"
SAS Converting SAS Dataset into XML ver Unix.sas

 

SAS Converting SAS Dataset into XML ver Unix.sas =

options fullstimer  noserror nomerror;


libname myReport "\\...\Documents\My SAS Files\work\Report";
libname mywork "\\...\Documents\My SAS Files\work";
%let MyReport1=\\...\Documents\My SAS Files\work\Report;
%let FileName=d2_fed_donn_fiscd_10000000;
%macro obscnt(dsn);
%global Gnobs;
%local dsnid;
%let nobs=.;
 
%* Open the data set of interest;
%let dsnid = %sysfunc(open(&dsn));
 
%* If the open was successful get the;
%* number of observations and CLOSE &dsn;
%if &dsnid %then %do;
     %let nobs=%sysfunc(attrn(&dsnid,nlobs));
     %let rc  =%sysfunc(close(&dsnid));
  %let Gnobs=&nobs;
%end;
%else %do;
     %put Unable to open &dsn - %sysfunc(sysmsg());
%end;
%mend obscnt;
%obscnt(mywork.&FileName.);
%put &gnobs;

/*Creating a Template*/
proc template;
%let Name=ROWSET;
%let Name2=ROW;
       define tagset tagsets.sasxnmis;/*Tagset Name*/
          parent = tagsets.sasxmnsp;/*Parent Tagset Name. This tagset erase blank before and afger instance tagset*/


   define event SASTable;/*Here we replace the SASTable named <TABLE> by <ROWSET>*/
        start:
           put "<&Name.>" NL;
           break;
  
        finish:
           put "</&Name.>" NL;
           break;
      end; /*End of the Define event SASTable*/
   define event SASRow;
         start:
            ndent;
            put "<";
            put UPCASE("&Name2.");
            put ">";
            put NL;
            break;

         finish:
            put "</";
            put UPCASE("&Name2.");
            put ">";
            put NL;
            xdent;
            break;
      end;
   define event SASColumn;/*This tagset add > and the variable name when data is missing*/
        start:
           ndent;
           put     '<' ;
           put     NAME;
           put '>'      / if exists(missing);
           break;
        finish:
           put '</'       ;
           put NAME       ;
           put '>'  CR    ;
           xdent;
           break;
        end;
   define event MLEVDAT;/* This tagset erase missing="." />*/
           break          / if exists(MISSING);
           put ' value="' / if cmp(XMLDATAFORM, "ATTRIBUTE");
           put VALUE      / if cmp(XMLDATAFORM, "ATTRIBUTE");
           put '"'        / if cmp(XMLDATAFORM, "ATTRIBUTE");
           break          / if cmp(XMLDATAFORM, "ATTRIBUTE");
           put '>'        ;
           put VALUE      ;
           break;
        end;
    
      end;  /*End of the define tagset*/
   run;
%macro split2(NbObsPerDst=,NobsTot=,FNameIn=,FNameOut=);
%let NbSubDiv=%sysevalf(&NobsTot./&NbObsPerDst.,ceil);/* Number of observation per split file*/

%do j=1 %to &NbSubDiv.;
libname newfile xmlv2 "&MyReport1.\&FNameOut._&j..xml"
tagset=tagsets.sasxnmis;
Data newfile.&FNameOut._&j;
set &FnameIn. (firstobs=%eval(((&j-1)*&NbObsPerDst)+1) obs=%eval(&j*&NbObsPerDst));;
run;
libname  newfile clear;
%end;
%mend split2;
%split2(NbObsPerDst=25000,NobsTot=&Gnobs.,FNameIn=mywork.&FileName.,FNameOut=testB);

1 ACCEPTED SOLUTION
1 REPLY 1

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1 reply
  • 1943 views
  • 0 likes
  • 1 in conversation