BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

I am trying to convert some string using encode64 but it does not seem to work.

 

length newString $200.;
%let client_id=cl8z50x6hs18bjfhvaiayktqb;
%let client_secret=c34e0aj4uokasfbe9zcgtcbjurt451mxzufyph7x3svn8i0htylg7dr1at4e;
newString=cats("&client_id.",":","&client_secret.");
call symputx('Basic_Auth',put(newString,$base64x64.));
%put &=Basic_Auth;
run;

Does someone know how to use this format

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You haven't posted working code so it is hard to tell what you are trying to do here.

To use data step statements, like CALL SYMPUTX() you need to have a data step.

Move any macro code to before or after the data step.

 

You defined NEWSTRING as length 200.  You should not pass the trailing spaces to the PUT() function.  You need to use a format width that is long enough to encode all 200 of those characters.

%let client_id=cl8z50x6hs18bjfhvaiayktqb;
%let client_secret=c34e0aj4uokasfbe9zcgtcbjurt451mxzufyph7x3svn8i0htylg7dr1at4e;

data _null_;
  length newString $200.;
  newString=cats("&client_id.",":","&client_secret.");
  call symputx('Basic_Auth',put(trim(newString),$base64x300.));
run;

%put &=Basic_Auth;

Result

423  %put &=Basic_Auth;
BASIC_AUTH=Y2w4ejUweDZoczE4YmpmaHZhaWF5a3RxYjpjMzRlMGFqNHVva2FzZmJlOXpjZ3RjYmp1cnQ0NTFteHp1ZnlwaDd4M3N2bjhpMGh0eWxnN2RyMWF0NGU=

Or you could just skip the data step code completely.

%let basic_auth=%sysfunc(putc(&client_id:&client_secret,$base64x300.));
%put &=Basic_Auth;

View solution in original post

2 REPLIES 2
ChrisHemedinger
Community Manager

When you say "it doesn't work" do you mean the result is not encoded, or that the API doesn't recognize it as valid?

 

Here's an example that I've used with a different API (Brightcove), but it may be similar to what Qualtrics needs.

 

data _null_;
length cred $ 128; 
 cred = "&client_id.:&client_secret.";
 call symputx('_bccred',put(trim(cred),$base64x256.));
run;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
Tom
Super User Tom
Super User

You haven't posted working code so it is hard to tell what you are trying to do here.

To use data step statements, like CALL SYMPUTX() you need to have a data step.

Move any macro code to before or after the data step.

 

You defined NEWSTRING as length 200.  You should not pass the trailing spaces to the PUT() function.  You need to use a format width that is long enough to encode all 200 of those characters.

%let client_id=cl8z50x6hs18bjfhvaiayktqb;
%let client_secret=c34e0aj4uokasfbe9zcgtcbjurt451mxzufyph7x3svn8i0htylg7dr1at4e;

data _null_;
  length newString $200.;
  newString=cats("&client_id.",":","&client_secret.");
  call symputx('Basic_Auth',put(trim(newString),$base64x300.));
run;

%put &=Basic_Auth;

Result

423  %put &=Basic_Auth;
BASIC_AUTH=Y2w4ejUweDZoczE4YmpmaHZhaWF5a3RxYjpjMzRlMGFqNHVva2FzZmJlOXpjZ3RjYmp1cnQ0NTFteHp1ZnlwaDd4M3N2bjhpMGh0eWxnN2RyMWF0NGU=

Or you could just skip the data step code completely.

%let basic_auth=%sysfunc(putc(&client_id:&client_secret,$base64x300.));
%put &=Basic_Auth;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 467 views
  • 1 like
  • 3 in conversation