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>
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.