I have a textbox that contains 2 fields with names in them, but the 2nd field can be empty. If there are 2 names I want it to display like this:
[name1], [name2]
if there is 1 name I want to display it like this:
[name1]
I have tried these 2 expressions:
=IIF(Fields!name2.Value Is Nothing, "", (", " + Fields!name2.Value))
=IIF(IsNothing(Fields!Joint_Name.Value), "", (", " + Fields!Joint_Name.Value))
however, in both cases if the 2nd name is blank it displays:
[name1],
any ideas how to get rid of that comma?
NULLs in your dataset usually come in as "".
=IIF(Fields!name2.Value = "", "", (", " + Fields!name2.Value))
I always recommend casting your Fields to the data type you intend to work with. A lot of the time the values come through in an unexpected data type and cause script errors.
=IIF(CSTR(Fields!name2.Value) = "", "", (", " + CSTR(Fields!name2.Value)))
Related
I have json data that looks like this:
{
"deploy:success": 2,
"deploy:RTX:success": 1,
"deploy:BLX:success": 1,
"deploy:RTX:BigTop:success": 1,
"deploy:BLX:BigTop:success": 1,
"deploy:RTX:BigTop:xxx:success": 1,
"deploy:BLX:BigTop:yyy:success": 1,
}
Where each new :<field> tacked on makes it more specific. Say a key with the format "deploy:RTX:success" is for a specific site RTX. I was planning on using a filter to show only the site-specific counts.
eval column_name=if($site_token$ = "", "deploy:success", "deploy:$site_token$:success")
Then rename the derived column:
rename column_name deploy
But the rename is looking for actual values in that first argument and not just a column name. I can't figure out how to get the values associated from that column for the life of me.
index=cloud_aws namespace=my namespace=Stats protov3=*
| spath input=protov3
| eval column_name=if("$site_token$" = "", "deploy:success", "deploy:$site_token$:success")
| rename column_name AS "deploy"
What have I done incorrectly?
It's not clear what the final result is supposed to be. If the result when $site_token$ is empty should be "deploy:success" then just use "deploy" as the target of the eval.
index=cloud_aws namespace=my namespace=Stats protov3=*
| spath input=protov3
| eval deploy=if("$site_token$" = "", "deploy:success", "deploy:$site_token$:success")
OTOH, if the result when $site_token$ is empty should be "2" then use the existing query with single quotes in the eval. Single quotes tell Splunk to treat the enclosed text as a field name rather than a literal string (which is what double quotes do).
index=cloud_aws namespace=my namespace=Stats protov3=*
| spath input=protov3
| eval deploy=if("$site_token$" = "", 'deploy:success', 'deploy:$site_token$:success')
How do I build an SSRS expression for the NoRowsMessage that shows report parameter values?
something like:
="No locations were found for this street name : " + #StreetName
I have also tried this:
="No locations were found for this street name : " + Parameters!StreetName.Value
The second attempt worked fine:
="No locations were found for this street name : " + Parameters!StreetName.Value
I can add in carriage returns also as per this article which suggests the use of vbcrlf
=vbcrlf + "No locations were found for this street name : " + Parameters!StreetName.Value
I came accross a strange problem:
When I use a simple expression like:
=iif(Fields!Length.Value = "", "empty", Fields!Length.Value)
then everything works, and I get my value, or the word "empty" in my report.
If I would change my expression to a sum of 2 times the length, then my "empty" would still appear.
=iif(Fields!Length.Value = "", "empty", (Fields!Length.Value + Fields!Length.Value))
But when I multiply, then my "empty" goes to #Error, While the rest of the data works fine...
=iif(Fields!Length.Value = "", "empty", (Fields!Length.Value * Fields!Length.Value))
Any idea? I find this behavior very, very weird.
Your problem is that IIF evaluates both the true and false results everytime, even if the false result won't be used in the final output. So it's trying to do
'' * ''
when you value is an empty string.
You can fix this by using VAL which will return the numeric value of the string first, like this.
=IIF(Fields!Length.Value = "", "empty", (VAL(Fields!Length.Value) * VAL(Fields!Length.Value)))
Tool: Microsoft Visual Studio 2013
I have an RDLC textbox expression where I want to split it based on ',' separated values and display those values in new line. For Example,
Value : Abc, Xyz, STU
The above value need to be displayed as :
Abc
Xyz
STU
I have tried the below expression:
IIf((Split(Parameters!rpField.Value,",").Length = 2),
Split(Parameters!rpField.Value, ",").GetValue(0) +System.Environment.NewLine+ Split(Parameters!rpField.Value,",").GetValue(1), "")
The result is #Error.
How can I accomplish this in SSRS?
Using the same structure you proposed, this worked for me:
=Split(CStr(Parameters!rpField.Value), ",").GetValue(0)
It looks like you just want to replace the commas with new lines, if you want them all in the same textbox?
If that is the case, you can simply use replace:
=replace("Abc, Xyz, STU", ", ", vbcrlf)
Have done it using Instr function and replaced ',' with NewLine as below:
=IIF(Parameters!rpField.Value <> "" ,iif(Instr(Parameters!Field.Value, ",") > 0 ,
" "+Replace(Parameters!rpField.Value,",",System.Environment.NewLine) +System.Environment.NewLine,
" "+Parameters!Field.Value+ System.Environment.NewLine) ,"")
Try this:
=JOIN(Split(Parameters!rpField.Value,","), System.Environment.NewLine)
This question is related to: prior question link
I have a JSON file that looks like:
[
{
"rxnorm_id": "999999999",
"drug_name": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"plans": [
{
"plan_id_type": "xxxxxxxxxxxxx",
"plan_id": "999999999999999",
"drug_tier": "xxxxxxxxxxxxxxx",
"prior_authorization": false,
"step_therapy": false,
"quantity_limit": false
},
I am able to import every line into SAS that has 'rxnorm_id and drug_name using this code:
>
filename data url 'http://stg-oh-medicaid.molinahealthcare.com/JSON/Drugs_Molina_Healthcare.json';
data formularies;
infile data lrecl = 32000 truncover scanover;
input #'"rxnorm_id": "' rxnorm_id $255.
#'"drug_name": "' drug_name $255.
#'"plan_id_type": "' plan_id_type $255.
#'"plan_id": "' plan_id $255.
#'"drug_tier": "' drug_tier $255.
#'"prior_authorization": ' prior_authorization $255.
#'"step_therapy": ' step_therapy $255.
#'"quantity_limit": ' quantity_limit $255.;
rxnorm_id = scan(rxnorm_id,1,'",');
drug_name = scan(drug_name,1,'",');
plan_id_type = scan(plan_id_type,1,'",');
plan_id = scan(plan_id,1,'",');
drug_tier = scan(drug_tier,1,'",');
prior_authorization = scan(prior_authorization,1,'",');
step_therapy = scan(step_therapy,1,'",');
quantity_limit = scan(quantity_limit,1,'",');
run;
But, I want to pick up all of the values in the 'plans' nest that are in between the rxnorm and drug name values. Someone suggested using the OUTPUT option in SAS to see the missing rows. Anyone got a good fix to my code to do this?
Thanks
As of 9.4, the best way to parse JSON in SAS is using PROC GROOVY. That is what I recommend. You can also do it with DS2. If you are adventurous, and on 9.4m3, you can also use PROC LUA. That is what I would try, since it allows you to manipulate SAS datasets easily.
That being said, if you can rely on the simple structure of your example, then you can select only the lines that have fields and output them in the format you wanted using regular expressions in data step:
data want;
infile 'c:/tmp/json_snippet.txt';
length field $20 data $100;
keep field data;
retain re;
input;
if _n_ = 1 then do;
re = prxparse('/"(.*?)": "?(true|false|.*?(?="))/');
end;
if prxmatch(re,_infile_); /* grep only matching lines */
call prxposn(re,1,start,len);
field = substr(_infile_,start,len);
call prxposn(re,2,start,len);
data = substr(_infile_,start,len);
run;
Caveat emptor: A wise person said that when you solve a problem using regular expressions, now you have two problems :). Among the things that can go wrong:
line breaks
using ' instead of " for string delimiters
lengths
mixed types