hello,
To create xml I write the following code:
data _null_;
set work.report end=eofl;
file "&OUTFILE./&FILE_NAME." NOPRINT encoding="utf-8";
by bankCode;
if _n_ =1 then
do;
put '<?xml version="1.0" encoding="utf-8"?>';
PUT '<currentDate>'currentDate'</currentDate>';
PUT '<factorCode>'factorCode'</factorCode>';
PUT '<monthReport>'monthReport'</monthReport>';
put '<banks>';
end;
if first.bankCode then
do;
put '<bank bankCode="' bankCode'">';
end;
put '<branch branchId="' branchId'">';
put '<cityId>'cityId'</cityId>';
put '<cashierDesk>'cashierDesk'</cashierDesk>';
put '<coreBankBranchId>'coreBankBranchId'</coreBankBranchId>';
put '<cashDepositBag>'cashDepositBag'</cashDepositBag>';
put '<nonAtmDepositMachine>' nonAtmDepositMachine'</nonAtmDepositMachine>';
put '</branch>';
if last.bankCode then
do;
put '</bank>';
end;
if eofl then
do;
put '</banks>';
put '</cashServicesReport>';
end;
run;
I want to remove blank spaces as shown by the arrows in the image, all fields come out with spaces.
Thanks.
I've run into a similar problem, and I need to use a +(-1) notation in the PUT step. See if this helps:
I've run into a similar problem, and I need to use a +(-1) notation in the PUT step. See if this helps:
Hello @shlomiohana,
I'd like to add that this is expected behavior of list output and explained in section How List Output Is Spaced of the PUT Statement: List documentation. As has been suggested, a column pointer control can be used to avoid the unwanted blanks (which do not occur with formatted output).
To abbreviate the repeating pattern in your code, you could write a little macro:
%macro item(var);
put "<&var>" &var +(-1) "</&var>";
%mend item;
Application:
data _null_;
set sashelp.class(obs=3);
%item(name)
%item(age)
run;
Result:
<name>Alfred</name> <age>14</age> <name>Alice</name> <age>13</age> <name>Barbara</name> <age>13</age>
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.