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

Tasked with parsing a 450+ encoded character string into SAS base64.
First was given the string, which I assigned to "lngstr" in a macro, then ran the string through "inputc(scan(lngstr,1)==,$base64x80);"                                                                                    
which works, (not really) as it only returns a partial result - no more than 61 characters.
Placing the same string in https://www.base64decode.org/ provides a completely different result, over 320 characters (I'm going with them as the correct answer).

Now I'm told these strings will be in a table from the client.                                                        
Making a test data set "Base64" with just one 454 length char string "lngstr" character variable, I'm having trouble using the $base64x80 function to generate any result at all. When I pasted the string into a variable in a macro and ran that variable through                        "inputc(scan(lngstr,1)==,$base64x80);" I got SOME result at least.       

                      

data _null_;                                                                                                                                  
set Base64;
length session_id $1500;
session_id=inputc(scan(lngstr,1)==,$base64x80);
run;                                                                                                                                            

Log states:                                                                                                                               

121 data _null_;
122 set Base64;

123 length session_id $1500;
124 session_id=inputc(scan(lngstr,1)==,$base64x80);
-
390
200
76
ERROR 390-185: Expecting an relational or arithmetic operator.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR 76-322: Syntax error, statement will be ignored.
125 run;                                                                                                                                        

My supervisor is saying maybe we should tell the client SAS can't do this as formated like this.
Is he right?
THANX.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Post the log in a text box opened on the forum using the </> icon to preserve formatting. The main message windows re-formats text so the diagnostic characters like the underscore in that error message no longer appears where it should. That location would be the place SAS first found something it could not process.

I'm going to guess it is under the equal sign where you use ==

 

Try

124 session_id=input(lngstr),$base64x80. ); 

Though I'm not sure how that works as you are not treating Lngstr as a macro variable as your description claims. Also you did not actually provide a Informat name which ends in . (period or dot) unless decimals are involved. InputC would accept an expression or variable that resolves to a valid Informat name but yours didn't. Plus I have no idea where that == comes from.

Modified from the online documentation of a test with this informat

data junk;
   x='d3d3Lm15ZG9tYWluLmNvbi9teWhpZGRlblVSTA==';
   val = input(x,$base64x80.);
   put val=;
run;

The 80 at the end of the informat basically says the result will be limited to 80 characters. So if you expect a longer value, say 1500 characters you should end the informat with 1500 not 80.

 

SCAN is going to return the characters up to the first of the following:

  • If your computer uses ASCII characters, the default delimiters are as follows:
    blank ! $ % & ( ) * + , - . / ; < ^ |
    In ASCII environments that do not contain the ^ character, the SCAN function uses the ~ character instead.
  • If your computer uses EBCDIC characters, then the default delimiters are as follows:
    blank ! $ % & ( ) * + , - . / ; < ¬ | ¢

So would could have truncated the input string as well.

View solution in original post

1 REPLY 1
ballardw
Super User

Post the log in a text box opened on the forum using the </> icon to preserve formatting. The main message windows re-formats text so the diagnostic characters like the underscore in that error message no longer appears where it should. That location would be the place SAS first found something it could not process.

I'm going to guess it is under the equal sign where you use ==

 

Try

124 session_id=input(lngstr),$base64x80. ); 

Though I'm not sure how that works as you are not treating Lngstr as a macro variable as your description claims. Also you did not actually provide a Informat name which ends in . (period or dot) unless decimals are involved. InputC would accept an expression or variable that resolves to a valid Informat name but yours didn't. Plus I have no idea where that == comes from.

Modified from the online documentation of a test with this informat

data junk;
   x='d3d3Lm15ZG9tYWluLmNvbi9teWhpZGRlblVSTA==';
   val = input(x,$base64x80.);
   put val=;
run;

The 80 at the end of the informat basically says the result will be limited to 80 characters. So if you expect a longer value, say 1500 characters you should end the informat with 1500 not 80.

 

SCAN is going to return the characters up to the first of the following:

  • If your computer uses ASCII characters, the default delimiters are as follows:
    blank ! $ % & ( ) * + , - . / ; < ^ |
    In ASCII environments that do not contain the ^ character, the SCAN function uses the ~ character instead.
  • If your computer uses EBCDIC characters, then the default delimiters are as follows:
    blank ! $ % & ( ) * + , - . / ; < ¬ | ¢

So would could have truncated the input string as well.

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
  • 1 reply
  • 227 views
  • 0 likes
  • 2 in conversation