- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 />';
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The MISSING() function just takes a value. The EQ keyword does not make sense there.
if missing(dpf_base) then
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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>';
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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>';
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please post sample data for your code so we can provide an actually tested solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.>
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.