BookmarkSubscribeRSS Feed
jp
Fluorite | Level 6 jp
Fluorite | Level 6

I'm trying to create an AWS signature, however I can't get my Line Feeds ('0a'x) to work exactly right when I'm trying to output a textfile of the string I want to hash. I'm using a textfile to check that the string (to be stored as a macro variable) is correct and can be hashed correctly.

 

Due to the line feeds not being exact it's causing the hash to be different from what I'm expecting (even when hashing the string directly)

 

Here's what I have currently; from googling around various documents:

 


data _null_;
  file "W:\sigtest.txt" TERMSTR=lf   recfm=v;
  signature = 'AWS4-HMAC-SHA256' || '0a'x ||
              '20150915T124500Z' || '0a'x ||
              '20150915/us-east-1/s3/aws4_request' || '0a'x || 
              'ef7c45cc2b0f100ea5d65024643f5cbaf83e7ba2717108905acd605cfe17bc6b';

  put signature;
run;

However when I check the output in notepad++ I get the following:

sig sas.PNG

 

When I'm expecting the following:

sig std.PNG

 

The extra line causes the hash to be different, however if I drop:

TERMSTR=lf   recfm=v

and use:

recfm=f

 I get the requisite number of lines (4), but I have trailing blanks/spaces after the hash key, which I can't get rid of.

sig sas2.PNG

 

Appreciate any help anyone has for this problem.

3 REPLIES 3
data_null__
Jade | Level 19

You need RECFM=N if you want to write your own term-string.  You also need a format you are getting a extra space using LIST PUT.

 

data _null_;
   file "~/sigtest.txt" recfm=n;
   signature = 'AWS4-HMAC-SHA256' || '0a'x ||
              '20150915T124500Z' || '0a'x ||
              '20150915/us-east-1/s3/aws4_request' || '0a'x || 
              'ef7c45cc2b0f100ea5d65024643f5cbaf83e7ba2717108905acd605cfe17bc6b';
   l=length(signature);
   put signature $varying256. l;
   run;
data _null_;
   infile "~/sigtest.txt" recfm=f;
   input;
   list;
   run;   

Capture.PNG

jp
Fluorite | Level 6 jp
Fluorite | Level 6

My colleague suggested the following solution:

 

data _null_;
  file "W:\sigtest.txt" TERMSTR=lf   recfm=F lrecl=1;
  signature = 'AWS4-HMAC-SHA256' || '0a'x ||
              '20150915T124500Z' || '0a'x ||
              '20150915/us-east-1/s3/aws4_request' || '0a'x ||
              'ef7c45cc2b0f100ea5d65024643f5cbaf83e7ba2717108905acd605cfe17bc6b';

  put signature;
run;

I will admit I'm not 100% sure how/why this is working but it seems to work. I'll take a look at your solution too data _null_.

 

data_null__
Jade | Level 19

RECFM N and F are similar in that there is no record termination string, RECFM=N has no record structure while RECFM=F has logical structure (an external attribute).  Standing on the outside looking in both files look them same because they are (tested with unix diff)

 

Your example writes 133 one byte records.  You can drop the INFILE statement option TERMSTR it is ignored.

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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2045 views
  • 0 likes
  • 2 in conversation