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;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 762 views
  • 1 like
  • 3 in conversation