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
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;
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;
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.