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

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.

shlomiohana_0-1636040579834.png

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

I've run into a similar problem, and I need to use a +(-1) notation in the PUT step. See if this helps:

 

https://communities.sas.com/t5/General-SAS-Programming/How-to-remove-trailing-blanks-when-PUT-statem...

View solution in original post

2 REPLIES 2
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

I've run into a similar problem, and I need to use a +(-1) notation in the PUT step. See if this helps:

 

https://communities.sas.com/t5/General-SAS-Programming/How-to-remove-trailing-blanks-when-PUT-statem...

FreelanceReinh
Jade | Level 19

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>

 

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

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1583 views
  • 0 likes
  • 3 in conversation