BookmarkSubscribeRSS Feed
Shantaram
Calcite | Level 5

I am trying to implement if condition inside XML file.

Sample code

 


proc sql;
create table transformed_data as
select * from mig_test.transformed_data;
quit;


data _null_;
set transformed_data;
file "$FSAGQS/BD/transfers2/TEST_Shan1.xml";
if _n_=1 then
do;
put '<?xml version="1.0" encoding="UTF-8"?>';
put '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:type="http://www.quinity.com/qis/soap/qisxmlpolicyrequestservice/type">';
put '<soapenv:Header />';
put '<soapenv:Body>';
put '<handlePolicyApplicationRequest>';
put '<policyRequest>';

Put '<applicationForm>';
Put '<applicationFormGroupList>';
put '<applicationFormGroup>';
put '<formGroupRef>';
put '<externalIdentifier>Startdate</externalIdentifier>';
put '</formGroupRef>';
put '<applicationFormQuestionList>';
put '<applicationFormQuestion>';
put '<formQuestionRef>';
put '<externalIdentifier>PolSTDT</externalIdentifier>';
put '</formQuestionRef>';
%if %superq(ID_01) ='' %then %Do;
put '<answer>';
put '<value/>';
put '</answer>';
%End;
%else %Do;
put '<answer>';
put '<value>' ID_01 +(-1) '</value>';
put '</answer>';
%end;
put '</applicationFormQuestion>';
put '</applicationFormQuestionList>';
put '</applicationFormGroup>';


put '<applicationFormGroup>';
put '<formGroupRef>';
put '<externalIdentifier>Productcode</externalIdentifier>';
put '</formGroupRef>';
put '<applicationFormQuestionList>';
put '<applicationFormQuestion>';
put '<formQuestionRef>';
put '<externlIdentifier>ProductName</externalIdentifier>';
put '</formQuestionRef>';
%if ID_02 IS MISSING %then %do;
put '<answer>';
put '</value>';
put '</answer>';
%end;
%else %do;
put '<answer>';
put '<value>' ID_02 +(-1) '</value>';
put '</answer>';
%end;
put '</applicationFormQuestion>';
put '</applicationFormQuestionList>';
put '</applicationFormGroup>';

put '</applicationFormGroupList>';
put '</applicationForm>';
put '</policyRequest>';
put '</handlePolicyApplicationRequest>';
put '</soapenv:Body>';
put '</soapenv:Envelope>';
end;
run;

 

4 REPLIES 4
Oligolas
Barite | Level 11

You've posted the same question here 

________________________

- Cheers -

Shantaram
Calcite | Level 5
Thanks Oligolas
Its with if statement and another one is with macro.
Oligolas
Barite | Level 11

I see,

 

so ID_01 is a numeric value from your dataset. In this case you do not need any macro code.

what you want instead of 

%if %superq(ID_01) ='' %then %Do;
put '<answer>';
put '<value/>';
put '</answer>';
%End;
%else %Do;
put '<answer>';
put '<value>' ID_01 +(-1) '</value>';
put '</answer>';
%end;

may be this:

if missing(ID_01) then Do;
   put '<answer>';
   put '<value/>';
   put '</answer>';
End;
else Do;
   put '<answer>';
   ID_01=ID_01+1;
   put '<value>' ID_01'</value>';
   put '</answer>';
end;
________________________

- Cheers -

Kurt_Bremser
Super User
%if %superq(ID_01) ='' %then %Do;

This condition will always be false, as the text ID_01 is always non equal to an empty string. Keep in mind that macro is a preprocessor that works on code long before that  code is executed; therefore, macro statements will never have access to the content of data step variables.

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
  • 4 replies
  • 1218 views
  • 0 likes
  • 3 in conversation