BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Of course you are getting two lines. You have two PUT statements.  One unconditional and then a second that only writes when the value is not missing.  So change:

put '    <dynamicPricingFactor>' dpf_base +(-1) '</dynamicPricingFactor>';
if dpf_base eq . then do;
  put '    <dynamicPricingFactor></dynamicPricingFactor>';
end;

to something like

if missing (dpf_base) then do;
  put '    <dynamicPricingFactor></dynamicPricingFactor>';
end;
else do;
  put '    <dynamicPricingFactor>' dpf_base +(-1) '</dynamicPricingFactor>';
end;

Note that for most XML uses you can use an abbreviated syntax in the XML file for the empty tags.  Like this:

  put '    <dynamicPricingFactor />';

 

 

View solution in original post

34 REPLIES 34
joao_moreira
Fluorite | Level 6

Hi,

 

Something like this would solve the issue:

 

 

if dpf_base eq "" then do;

put '    <dynamicPricingFactor></dynamicPricingFactor>';
end;
else do;
put '    <dynamicPricingFactor>' dpf_base +(-1) '</dynamicPricingFactor>';
end;

 

 

Or are you looking for something else?

 

Best Regards,

Joao Moreira.

Babloo
Rhodochrosite | Level 12

It´s not working as in the output XML file I see as <dynamicPricingFactor>.</dynamicPricingFactor>. I placed the following code before the code snippet which I gave in the initial post. Appreciate if could help me further.

 

	if dpf_base eq "" then do;

put '    <dynamicPricingFactor></dynamicPricingFactor>';
end;
else do;
put '    <dynamicPricingFactor>' dpf_base +(-1) '</dynamicPricingFactor>
joao_moreira
Fluorite | Level 6

I assume that's because dpf_base is numeric. Is that rigth?

 

If so the code should be:

 

if dpf_base eq . then do;
put '    <dynamicPricingFactor></dynamicPricingFactor>';
end;
else do;
put '    <dynamicPricingFactor>' dpf_base +(-1) '</dynamicPricingFactor>';
end;

Best Regards,

Joao Moreira

 

EDIT (@Reeza) correct a double quote to single quote.

Patrick
Opal | Level 21

or you use the missing() function which works for both numeric and character

if missing(dpf_base eq) then do;

 

Instead of writing this XML using data step put statements it might also be worth testing if the libname XMLV2 engine could generate an acceptable result.

libname test xmlv2 'c:\test\test.xml';
data test.class;
  set sashelp.class;
  if _n_=2 then call missing(name);
run;
Babloo
Rhodochrosite | Level 12

Could you please help me to resolve this error?

 

60         		if missing(dpf_base eq) then
                                   _
                                   390
                                   76
ERROR 390-185: Expecting an relational or arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

61         do;
62         put '    <dynamicPricingFactor></dynamicPricingFactor>';
63         end;
           ___
           161
ERROR 161-185: No matching DO/SELECT statement.
Tom
Super User Tom
Super User

The MISSING() function just takes a value.  The EQ keyword does not make sense there.

if missing(dpf_base) then
Babloo
Rhodochrosite | Level 12
I think the tricky part is where we adding that if clause. Could you please
help me understand where should I add the If clause? Is it at the
beginning of the code or in between the code which I shared in the initial
post?
Babloo
Rhodochrosite | Level 12

I have the placed below the snippet of SAS program  which will convert the SAS dataset to XML file. However when I do, the field dpf_base is not filled in in the SAS dataset but the field <dynamicPricingFactor> in the xml file is filled in with a ‘.’  instead of leaving it as empty. Appreciate if someone of you guide me to resolve this issue.

 

put '<dynamicPricingFactorPolicyCover>';
	put   '<productVersionCoverRef>';
	put '    <externalIdentifier>'  cover +(-1) '</externalIdentifier>';
	put '   </productVersionCoverRef>';
	put '    <isForNonMatch>false</isForNonMatch>';
	put '    <hashCode1>'  veh_driver_hashcode +(-1)  '</hashCode1>';
	put '    <hashCode2>' version_subversion_hashcode +(-1) '</hashCode2>';
	put '    <dynamicPricingFactor>' dpf_base +(-1) '</dynamicPricingFactor>';
	put '    <dynamicPricingFactorPolicyCoverLangList>';
	put '       <dynamicPricingFactorPolicyCoverLang>';
	put '            <languageRef>';
	put '                 <externalIdentifier>FR</externalIdentifier>';
	put '            </languageRef>';
	a=translate(expl_base,'-','/');
	put '            <explanation>' a '</explanation>';
	put '        </dynamicPricingFactorPolicyCoverLang>';
	put '        <dynamicPricingFactorPolicyCoverLang>';
	put '            <languageRef>';
	put '                 <externalIdentifier>VLS</externalIdentifier>';
	put '            </languageRef>';
	put '            <explanation>' a '</explanation>';

	*put '            <explanation>' translate(expl_base,'-','/') '</explanation>';
	put '        </dynamicPricingFactorPolicyCoverLang>';
	put '    </dynamicPricingFactorPolicyCoverLangList>';
	put ' </dynamicPricingFactorPolicyCover>';
Reeza
Super User

Set option missing=‘’;

or add an IF statement to conditionally put the value or missing

or use COALESCE to determine the actual value to handle the missing value.

 


@Babloo wrote:

I have the placed below the snippet of SAS program  which will convert the SAS dataset to XML file. However when I do, the field dpf_base is not filled in in the SAS dataset but the field <dynamicPricingFactor> in the xml file is filled in with a ‘.’  instead of leaving it as empty. Appreciate if someone of you guide me to resolve this issue.

 

put '<dynamicPricingFactorPolicyCover>';
	put   '<productVersionCoverRef>';
	put '    <externalIdentifier>'  cover +(-1) '</externalIdentifier>';
	put '   </productVersionCoverRef>';
	put '    <isForNonMatch>false</isForNonMatch>';
	put '    <hashCode1>'  veh_driver_hashcode +(-1)  '</hashCode1>';
	put '    <hashCode2>' version_subversion_hashcode +(-1) '</hashCode2>';
	put '    <dynamicPricingFactor>' dpf_base +(-1) '</dynamicPricingFactor>';
	put '    <dynamicPricingFactorPolicyCoverLangList>';
	put '       <dynamicPricingFactorPolicyCoverLang>';
	put '            <languageRef>';
	put '                 <externalIdentifier>FR</externalIdentifier>';
	put '            </languageRef>';
	a=translate(expl_base,'-','/');
	put '            <explanation>' a '</explanation>';
	put '        </dynamicPricingFactorPolicyCoverLang>';
	put '        <dynamicPricingFactorPolicyCoverLang>';
	put '            <languageRef>';
	put '                 <externalIdentifier>VLS</externalIdentifier>';
	put '            </languageRef>';
	put '            <explanation>' a '</explanation>';

	*put '            <explanation>' translate(expl_base,'-','/') '</explanation>';
	put '        </dynamicPricingFactorPolicyCoverLang>';
	put '    </dynamicPricingFactorPolicyCoverLangList>';
	put ' </dynamicPricingFactorPolicyCover>';

 

Reeza
Super User

You add the clause where you output the statement. 

 

IF <> then do;

put ...

end;

else do;

put ...

end;

 


@Babloo wrote:
I think the tricky part is where we adding that if clause. Could you please
help me understand where should I add the If clause? Is it at the
beginning of the code or in between the code which I shared in the initial
post?



Babloo
Rhodochrosite | Level 12

Still the issue seem to be not resolved. I just compared the output after (right)  and before (left) updating the code and screenshot below for quick reference. I´m getting two extra lines (red highlighted in right side) as you seen below.

 

Code which I added is,

 

if dpf_base eq . then do;
put '    <dynamicPricingFactor></dynamicPricingFactor>';
end;

Output Comparision:

 

Comparison.PNG

Patrick
Opal | Level 21

@Babloo

Please post sample data for your code so we can provide an actually tested solution.

ChrisNZ
Tourmaline | Level 20

Additional lines make no sense.

You replace one put statement with another, so you'll have the same number of lines.

 

if missing(dpf_base) then 
  put '    <dynamicPricingFactor></dynamicPricingFactor>';
else 
  put '    <dynamicPricingFactor>' dpf_base +(-1) '</dynamicPricingFactor>";
 
  instead of 

  

put '    <dynamicPricingFactor>' dpf_base +(-1) '</dynamicPricingFactor>";

 

<sorry for the spam, the formatting keeps getting butchered.>

Reeza
Super User

SAS OPTIONS go outside of the PROC. Put the option before the data step and it should work fine. 

 

Im assuming you have data step code somewhere since none is shown. 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 34 replies
  • 1438 views
  • 14 likes
  • 6 in conversation