I am trying to write a PROC HTTP program to validate Zip+4 for mailing addresses using PROC HTTP and the USPS API webtools. I have a successful HTTP URL that I need to replicate with PROC HTTP. The program creates an XML library to format the addresses for validation but I am getting an XML syntax error when run the PROC HTTP. The URL I am trying to reproduce returns an XML response record without error.
http://production.shippingapis.com/ShippingAPI.dll?API=Verify
&XML=<AddressValidateRequest USERID="165THEQU4205"><Address ID="0"><Address1></Address1>
<Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State>
<Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
test program that returns an XML Error Response Message:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Number>80040B19</Number><Description>XML Syntax Error: Please check the XML request to see if it can be parsed.</Description><Source>USPSCOM::DoAuth</Source></Error>
SAS code:
libname test xml "/sasuser.v94/AddressValidateRequest.xml";
filename in "/sasuser.v94/AddressValidateRequest.xml";
filename out "/sasuser.v94/AddressValidateResponse.xml";
data test.Address;
Revision=1; ID=1; Address1=''; Address2='6406 Ivy Lane'; City='Greenbelt';
State='MD';
run;
* Pass information to USPS API webtool for processing;
proc http
url="https://stg-secure.shippingapis.com/ShippingAPI.dll?API=AddressValidateRequest"
webusername="165THEQU4205"
webpassword="120RW00US168"
method="POST"
in=in
out=out;
run;
I don't see where &xml is used.
Oh sorry. You formatted your question badly.
The link is
http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="165THEQU4205"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
There is no macro variable.
What happens if you use http instead of https?
What happens if you use method GET?
What happens if you use
proc http url='http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="165THEQU4205"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>' ?
The site only accepts https: queries.
The API User manual recommends using POST as the request method
specifying the full URL in the PROC HTTP statement causes a SAS syntax error. Also, this will not solve root problem since I would like to make the requests dynamic and, if possible, automated from a database query by using the in= clause.
> The site only accepts https: queries. The API User manual recommends using POST as the request method
Pasting
http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="165THEQU4205"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
in a browser works, so maybe the constraints are not as hard as they seem.
> Also, this will not solve root problem since I would like to make the requests dynamic
You can still make the query dynamic, for example with a call execute.
I can't run proc http, so these were just ideas for you to test. Feel free to ignore 🙂
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.