JMeter: comparing ASCII character - compare

When I run Jmeter, a test case fails because it compares unwanted ASCII character
following is the result:
Data '£107.29K' is missing;
Data '£131.72K' is missing;
Data '£67.05K' is missing;
Data '£93.84K' is missing;
Data '£107.29K' is new;
Data '£131.72K' is new;
Data '£67.05K' is new;
Data '£93.84K' is new;
When I check the responses, there is no such character in expected response. Not any difference is shown in comparing the responses.
How can I skip this comparison?

Try coverting your string to utf-8
byte[] utf8Bytes = original.getBytes("UTF8");
String roundTrip = new String(utf8Bytes, "UTF8");
You can refer this https://docs.oracle.com/javase/tutorial/i18n/text/string.html

Related

In SAS compute an md5 hash for whole file given you have an md5 hash for each record

This is a follow-up to my recent question on calculating md5 hash in SAS and python. So, I'm using SAS v9.2 and there is an md5 hash function which takes in a string and returns a hash. What I'd really like though is a way to compute the hash for the file as a whole. Given that I have a hash for each record , is there any way to do this and have the file hash match up with the value obtained by using , say, python code. Taking the sashelp.shoes dataset as an example I exported this to a CSV file and manually removed double quotes and dollars and commas of the currency fields. I then computed the hash for the file as a whole using this python code:
filename = "f:/test/shoes.csv"
md5_hash = hashlib.md5()
with open(filename,"rb") as f:
# Read and update hash string value in blocks of 4K
for byte_block in iter(lambda: f.read(1024*1024),b''):
md5_hash.update(byte_block.replace(b'\r', b'').replace(b'\n', b''))
print(md5_hash.hexdigest())
And got this hash back as output:
f7f205b5b844bf57f5f51685969e0df0
If anyone can replicate this final hash value in SAS for that dataset that would be great.
PS I'm on SAS V9.2
You have two options:
Implement the MD5 algorithm in SAS. I'm aware of existing implementations for SHA and CRC but I'm not sure about MD5.
Call an external utility from SAS to calculate the md5 hash for the file. There is an example here.
My earlier note on limitations applies only when working with DS1. There is no way around the length restriction in DS1. You could try this and you will get an error:
data test;
length x $30000;
x = repeat('-', 30000);
run;
data _null_;
set test;
format m $hex32.;
m = md5(catx(',', x, x));
put m=;
run;`
But Robert Pendridge is correct to point out that DS2 can solve this issue.
%let reclen = 201; /* Length of each record */
%let records = 2000; /* Number of records */
%let totlen = %eval(&reclen * &records);
proc ds2;
data _null_;
retain m;
dcl char(&totlen) m;
method run();
dcl char(200) c;
set shoes;
c = catx(',',&varstr2);
m = strip(m)|| strip(c);
end;
method term();
dcl char(32) hh;
hh = put(md5(m), $hex32.);
put hh=;
end;
enddata;
run;
quit;
This is essentially doing what the Python code is doing. The update merely concatenates the strings and applies the hash. You may have to tighten this up a little bit to remove any extraneous spaces etc., but should work.
Unfortunately you cannot in DS1. The reason is that the maximum variable size that SAS allows is only 32,767 bytes long. You could group the variables in multiple variables, but still when you try to concatenate them (even directly when invoking the md5 function), it will end up truncating it. Your best bet is writing the output to an external text file (as shown below based on your previous example) and generating md5sum on it. This is actually just one little extra step.. You could just use the X command to do that from within SAS itself (provided you are configured to do so).
filename ff "contents.txt" TERMSTR=CR;
data _null_;
set shoes end = lastrec;
newvar2 = catx(',',&varstr2);
file ff;
put newvar2;
run;

Why can't I use length function inside input function in SAS?

I have a code that converts a character to numeric using the informat and I'm using length function as the value of informat.
However, I'm having error with this approach.
Background of this problem is that the informat before was fixed value. I want to enhance the code for the informat to be flexible and remove the fixed value.
Before code:
data work.test;
emp_input = '168643123'
emp_value = input(emp_input, 6.);
run;
My current testcode:
data work.test;
emp_input = '168643123'
emp_value = input(emp_input, length(emp_input).);
run;
I expect the result that character '168643123' would be converted to numeric 168643123.
Using before code the output for this would be: numeric 168643.
That is not valid syntax. You have to use inputn an and then generate an string for the format.
data work.test;
emp_input = '168643123';
emp_value = inputn(emp_input, cats(put(length(emp_input),3.),'.'));
run;
But better use Use BEST32. for all generic numbers of up 32 chars length.
data work.test;
emp_input = '168643123';
emp_value = input(emp_input, BEST32.);
run;
INPUT requires a text value for the second parameter.
INPUTN() or INPUTC() can take the second parameter as a string/character/variable and use that to apply the format. You do have to convert it to a string first.
Why? The INPUT function is happy to adjust when the width of the informat is larger than the length of the string you are reading. Just use the maximum width that the informat allows.
emp_value = input(emp_input,32.);
If you did want to limit the number of characters read (perhaps there are letters after the digits?) then you can use the INPUTN() function (or INPUTC() function for character results). Let's test by appending some X's to the end of the string and using an informat whose width stops before the X's.
emp_value = inputn(cats(emp_input,'XXX'),cats(length(emp_input),'.'));
This code worked for me. This is based on all your answers. Thank you very much!
data work.test;
emp_input = '168643123'
emp_value = inputn(emp_input, cats(length(emp_input),'.'));
run;

Convert Number with Format into a String

How do you convert a number or currency variable into a character string that keeps the format as part of the string?
For instance, the below code has a character variable, MSRP_to_text, and currency variable, MSRP. When I set MSRP_to_text equal to MSRP, it takes the unformatted number and converts it to a string, so the dollar sign and the comma are gone.
DATA want;
SET SASHELP.CARS(KEEP=MSRP);
ATTRIB MSRP_to_text FORMAT=$8.;
MSRP_to_text = MSRP;
RUN;
In other words, the code is currently converting $36,945 -> "36945", but what I really want is $36,945 -> "$36,945".
Is there a way to keep the dollar sign and comma in the string?
VVALUE function will retrieve the formatted value of a variable.
MSRP_as_text = VVALUE(MSRP);
VVALUEX goes one step further for the case of the variable name being dynamic; such as being stored in a different variable, or is computed from some name patterning algorithm.
name = 'MSRP';
formatted_value = VVALUEX(name);
Instead of ATTRIB statement, Use the PUT function to convert number to Character. and it will keep the text value with format. Since the original Format of MSRP is DOLLAR8. , so using same format in put statement will suffice the purpose
DATA want;
SET SASHELP.CARS(KEEP=MSRP);
MSRP_to_text = put(MSRP, DOLLAR8.);
RUN;
proc contents data=want; run;

data driven put with different formats challenge

I wanted to come here with this challenge I'm facing in these days.
Basically for each record, a different format should be used in a put statement, and it is defined in the data in theirselves.
The challenge is not to split the datasteps and gaining the wanted result within the datastep, so avoid obvious %do loops and similar :)
proc format;
value $a 'FRS'='FIRST';
value $b 'SCN'='SECOND';
run;
data a;
length var $3 res $10 fmt $5;
var='FRS'; fmt='$a.'; res=''; output;
var='SCN'; fmt='$b.'; res=''; output;
run;
data b;
set a;
*your code goes here, the result should go into res variable;
*and should be the "putted" value of var using fmt as format.;
*an obviously non working version can be found here below;
res=put(var,fmt);
run;
Here below what it looks like, res is the expected result:
VAR FMT RES
---------------
"FRS" $a. =put("FRS",$a.)="FIRST"
"SCN" $b. =put("SCN",$b.)="SECOND"
I am not sure I understand the question, but it looks like you just want to use the PUTC() function. If your variable was numeric you would use the PUTN() function instead.
res=putc(var,fmt);

Need Clarification in NEGPARENw.d

The NEGPARENw.d reads the values -2000 as (20,00) based on the w.d
is there anyway to do the same in SAS 9.1?
I read a value 00005000- as character value and then converted to numeric value
-5000
TEMP=000005000-
Temp= COMPRESS(TEMP,'-')
TEMP=-(INPUT(TEMP,16.2)) format NEGPARENw.d its not working
PRoc report;
.....
define temp /display format = NEGPAREN16.2
Run;
Thanks
NEGPARENw.d format exists in 9.1.3, so there's no particular reason it wouldn't work the same in 9.1.3 as it would in later versions.