BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
putteringpluie
Obsidian | Level 7

I have the following code which fails if users have the character '&' in their password (myPW).

 

I know that data _null_ statement is working as expected 'input' is resolving to the correct string. The problem seems to be in the 'in=' statement in proc http. How do I make sure that the correct string is being input in proc http?

 

 

filename input TEMP;
filename resp TEMP;
filename headers TEMP;


%LET myPW=%STR(xxxxxx);
%LET myID=%STR(xxxxxx);

data _null_;
	file input recfm=f lrecl=1;
	put "RS_action=signOn%nrstr(&RS_userName)=&myID.%nrstr(&RS_password)=&myPW";
run;




proc http
	method="POST"
	url="http://xxxxx:####"
	in=input
	headerout=headers
	out=resp
	HEADEROUT_OVERWRITE;
run;

SAS version 9.4

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The use URLENCODE() function to convert the string before writing it.
Or possible you want the HTMLENCODE() function instead.

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

You need to show what you think the resulting text should look like.

If you want to use & in your strings without SAS thinking you want to reference a macro variable then why not just use single quotes?

Also not sure how you expect SAS write such a long string to a file that has records of only 1 byte each?

%LET myPW=%STR(xxxxxx);
%LET myID=%STR(xxxxxx);

data _null_;
  file input ;
  put 'RS_action=signOn&RS_userName=' "&myID." '&RS_password=' "&myPW";
run;

 

putteringpluie
Obsidian | Level 7

Thank you for the reply. 

It gives me the same result as the original code. It works for passwords that do not have '&' character, but fails if the password has that character. When I look at 'input', the password is resolving correctly though. 

Tom
Super User Tom
Super User

The use URLENCODE() function to convert the string before writing it.
Or possible you want the HTMLENCODE() function instead.

putteringpluie
Obsidian | Level 7
Thank you. Searching for urlencode lead me to this: https://blogs.sas.com/content/sasdummy/2018/04/04/htmlencode-urlencode/.

Which told me that I have to use urlencode function so I can 'eecape' the ampersand symbol in my code. Adding that funtion to my password variable helped me resolve this issue.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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