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;
You've posted the same question here
- Cheers -
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 -
%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.
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!
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.