BookmarkSubscribeRSS Feed
Felix
Calcite | Level 5

Does anyone know how to change a Dashboard Range Dynamically? I need the numbers to display and they need to change each month. I can type them in manually, but it is very time consuming.

1 REPLY 1
MDU_BRFkredit
Calcite | Level 5

Hey Felixor or others with similar problem.

I got a solutions delivered from SAS (Falko Schulz), that can update the Dashboard Range. It is base SAS codes that can be scheduled to run monthly/daily etc.

The code uses metadata to update the Dashboard Range:


/*--------------------------------------------------------------------------*/
/* Program: update_bid_43_ranges.sas                                        */
/* Purpose: updates existing range definitions based on a dataset           */
/* Author: Falko.Schulz@sas.com, SAS Institute Australia, 5 Jul 2010        */
/* Modified: Falko.Schulz@sas.com, SAS Institute Australia, 23 Oct 2010     */
/*--------------------------------------------------------------------------*/

%let davRangeFile=Country Sale Range 2.rdx;
%let davPath=http://localhost:8080/SASContentServer/repository/default/sasfolders/Projects/Dashboards/Sales by Country/;
%let davUser=sasadm@saspw;
%let davPass=Orion123;
%let locale=DK;

/* metadata server logon details */
options metaserver="localhost"
  metaport=8561
  metauser="&davUser."
  metapass="&davPass."
  metarepository="Foundation";

/* file reference to the range definition in webDAV */

filename davfile webdav "&davPath." dir user="&davUser." pw="&davPass.";

/* sample - range data */
data rangedata;
input id label $ 4-32 ccode $ 33-47 color $ 48-53 lower upper;
datalines;
1  Well Below Target            belowTarget    d06959 . 100
2  Below Target                 belowTarget    d06959 100 200
3  On Target                    onTarget       f1dc63 200 300
4  Above Target                 aboveTarget    84af5b 300 400
5  Well Above Target            aboveTarget    84af5b 400 .
;
run;

/* re-use first part of the existing file until we find the <Intervals> tag */
data part1;
length doc $32576.;
infile davfile("&davRangeFile.(Range)");
input;
doc=_infile_;
output;
if (compress(_infile_) eq "<Intervals>") then stop;
run;

/* generate the second part based on the range data definition */
data part2(keep=doc);
length doc $32576.;
set rangedata end=last;

if _n_ eq 1 then do;
  doc='<Interval classificationCode="' || trim(ccode) || '" lowerBoundInclusive="false" upperBound="'
    || compress(put(upper,8.)) || '" upperBoundInclusive="false" color="' || trim(color) || '">';
end; else do;
  doc='<Interval classificationCode="' || trim(ccode) || '" lowerBound="' || compress(put(lower,8.)) || '"
            lowerBoundInclusive="true" upperBound="' || compress(put(upper,8.)) || '"
            upperBoundInclusive="false" color="' || trim(color) || '">';
end;
output;

doc= '<LocalizedTextBundle><LocalizedTextLists><LocalizedTextList language="en" country="' || "&locale." || '"><LocalizedTexts><LocalizedText id="name">';output;
doc= '<text>' || trim(label) || '</text>';output;
doc= '</LocalizedText></LocalizedTexts></LocalizedTextList></LocalizedTextLists></LocalizedTextBundle></Interval>';output;

if last then do;
  doc= '</Intervals>';output;
  doc= '</RangeDefinition>';output;
end;
run;

/* combine both parts and write back to webDAV */
data _null_;
set part1 part2;
file davfile("&davRangeFile.(Range)");
put doc;
run;

/* update the metadata object timestamp to initiate refresh of the object in BID */
data _null_;
    length uri $256 conuri $256 val $256 name $256 id $256;
    nobj=0;
    n=1;
    uri="";

    do while (nobj >= 0);
        nobj=metadata_getnobj("omsobj:Transformation?Transformation[@Name='&davRangeFile.' and @PublicType='Range']",n,uri);
        if (nobj >= 0) then do;
      rc=metadata_getattr(uri, "Name", name);
   rc=metadata_getattr(uri, "Id", id);
   rc=metadata_setattr(uri, "Name", name);
      put "Range definition '" name "' [" id "] updated.";
        end;
        n = n + 1;
    end;

run;

/* DEBUG:: dump xml to the log for validation */
data range;
  infile davfile("&davRangeFile.(Range)");
  input;
  put _infile_;
run;

filename davfile;


hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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