Im creating an HTML file from SAS like the following
data _null_;
file './test.html';
put '<DOCTYPE html>';
put '<html>';
put '<script>'
put '</script>'
put '</html>'
The problem is that I need to take a SAS dataset, convert it to JSON format and insert it into the HTML file. The pseudo code is:
data _null_;
file './test.html';
put '<DOCTYPE html>';
put '<html>';
put '<script>';
sasDataFrame -> to Json
put 'console.log(sasDataFrame)';
put '</script>'
put '</html>'
I know that proc JSON allows me to convert SAS dataset to Json, but i don't know how to embed the string result into an HTML through this sort of put statement.
Anyone knows how to accomplish this?
Create the JSON file as a text file using PROC JSON or whatever method you want. Then write the contents of that file into your HTML file.
So let's assume you have pointed the fileref JSON to file with the JSON text in it.
Now first write the header information, then the contents of the file, then the trailing information.
With your simple example you could do it all in one data step. Just read the lines from the JSON text file and write them to the HTML file you are creating.
data _null_;
file './test.html';
if _n_=1 then put
'<DOCTYPE html>'
/ '<html>'
/ '<script>'
;
if eof then put
'</script>'
/ '</html>'
;
infile json end=eof;
input;
put _infile_;
run;
For more complex file generation you can use multiple data steps to construct the HTML file. Just use MOD option on the FILE statement to append text to an existing file instead of making a new file.
Streaming web content like this is an antipattern!!
Rather than fiddle around with put statements, why not serve your index.html through the web server, and send the data from SAS directly as a pure JSON payload?
Here's a repo we created that will let you talk to SAS from frontend: https://github.com/sasjs/adapter
And here's another one with a ready-made web app you can use as a starting point: https://github.com/sasjs/minimal-seed-app
Whilst plugging SASjs (an open source tool my team created) I'll also point out that by using this approach you can easily deploy and run your web app on Viya and Base SAS as well as SAS 9 BI. It'll also run much faster and be easier to maintain.
Related
I have added CSV file to SharePoint Documents library.
I needs to read that CSV file using Power Automate / Flow.
I have created Power Automate flow. Below is the screenshot fro the same.
Which CSV parser do i need to use for read data from file content action?
Can anyone help me for the same?
Thanks
If you want to retrieve the content of the CSV without a premium connector you could use an expression to convert the $content property of the Get File Content action into a string value. You can use the base64tostring function for this.
Below is an example
base64tostring(outputs('Get_file_content')?['body']['$content'])
I need to get whole text from csv file using CSV Data Set Config at once.
You cannot, if you want to load the whole file into certain place in the Test Plan or into a JMeter Variable you can use __FileToString() function and provide the relative or full path to the CSV file like:
${__FileToString(/path/to/your/file.csv,,)}
if you want to save the file into the variable just provide the variable name as the last parameter:
${__FileToString(/path/to/your/file.csv,,foo)}
Check out Apache JMeter Functions - An Introduction article to learn more about JMeter Functions concept
I'm new to Jmeter so I hope this question is not too off the wall. I am trying to test an HTTP endpoint that accepts a large JSON payload and processes it. I have collected a few hundred JSON blobs in a file and want to use those as my input for testing. The only way that I have come across for loading the data is using the CSV config. I have a single line of the file for each request. I have attempted to use \n as a delimiter and have also tried adding a tab character \t to the end of each line. My requests all show in put of<EOF>.
Is there a way to read a file of JSON objects, line at a time, and pass them to my endpoint as the body in a POST?
You need to provide more information, to wit: example JSON file (first 2 lines), your CSV Data Set Configuration, jmeter.log file, etc. so we could help.
For the time being I can state that:
Given CSV file looking like:
{"foo":"bar"}
{"baz":"qux"}
And pretty much default CSV Data Set Config setup
JMeter normally reads the CSV data
Be aware that there are alternatives to the CSV Data Set Config, for example:
__CSVRead() function. The equivalent syntax would be ${__CSVRead(test.csv,0)}
__StringFromFile() function. The equivalent syntax would be ${__StringFromFile(test.csv,,,)}
See Apache JMeter Functions - An Introduction to get familiarized with the JMeter Functions concept.
How can I make JMeter read the second sheet of my CSV?
I want to use CSV Data Set Config.
Normally, it reads the first line of the first sheet but is there any way to be a bit more flexible?
CSV file format doesn't have "sheets", it is a normal plain text file using delimiters in order to represent structured data.
If you are trying to get data from i.e. Microsoft Excel file type - unfortunately you won't be able to do it using CSV Data Set Config. The easiest would be exporting data as separate plain-text CSV files.
If you don't have the possibility to do the export you still can access the data from Excel files but it will be a little bit more tricky as you will have to use JSR223 Test Elements, Groovy language and Apache POI libraries
More information:
Busy Developers' Guide to HSSF and XSSF Features
How to Extract Data From Files With JMeter
Currently you can use CSV Data Set Config for that, you should add external code for example using Apache Commons CSV,
Download the jar file and place it in JMETER_HOME lib folder, and then write the code in JSR223 Element.
Examples exists, code for get second record:
Reader in = new FileReader("path/to/file.csv");
Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(in);
// go to next record
records.next();
CSVRecord secondRecord = records.next();
//columnOne = secondRecord.get(0);
I'm hoping to store data I get from a server which sends data via JSON. I don't want anything fancy - just would like to save the data so I can play with it in excel.
Here is the JSON URL: http://realm3.castle.wonderhill.com/api/map.json
I'm extremely surprised there are no solutions out there on this yet.
What would you guys used to achieve this?
Convert the json into a text file formatted as CSV - Excel can read that. I'll come up with some sample code in PHP after dinner.
EDIT: Bah, dinner can wait.
<?php
// Download data to a string
$mapData = file_get_contents('http://realm3.castle.wonderhill.com/api/map.json');
// Convert JSON into an Array
$mapData = json_decode($mapData);
var_dump($mapData);
echo "\n";
Saved the above into test.php and then ran it like this:
php test.php | less
and the output is a huge data structure. You'll need to extract what you want and then use fputcsv() to write the content to a file that you'll then read into Excel. The output doesn't seem to have any special characters, but if you do have a problem make sure to encode the data as CP1252 so Excel for Windows can read it.