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>

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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