Search code examples
sasanalytics

SAS VA Counting Pages in Report


i just wanna ask simple questions, is there a way to count all pages in report automatically?

I need it to get some kind of overview for all my reports to simplify the process of getting informations. Thanks for your responses advices etc...


Solution

  • You can download the report itself and identify the pages within the VA XML. Depending on which version of VA you use, you'll either need to query the metadata server directly or download the report from Viya. Here is how you can download it on 9.4 or Viya.

    Once you get the XML, all pages start with one of the following tags:

    <Section name= <HiddenSection

    Once you download the XML you can parse it to find these and count them. For example:

    <Section name="vi6" label="Page 1">
        <Body>
            ...
        </Body>
    </Section>
    <HiddenSection width="50%" height="50%" purpose="information" name="vi7" label="Page 2">
        <Body>
            ...
        </Body>
    </Section>
    <HiddenSection purpose="hidden" name="vi8" label="Page 3">
        <Body>
            ...
        </Body>
    </Section>
    

    The following SAS code will do this:

    data want;
        infile "/path/to/file/report.xml" lrecl=32676 length=len end=eof;
        input line $varying32767. len;
    
        if(   find(upcase(line), '<SECTION NAME=')
           OR find(upcase(line), '<HIDDENSECTION')
          ) 
        then total_pages+1;
    
        if(eof);
    
        drop line;
    run;
    

    Alternatively, you can use the Viya API to get report content elements and count the number of times that the variable type contains the word Section in the returned JSON item list.

    You can test this in your browser by navigating to:

    https://your-viya-server.com/reports/reports/{reportID}/content/elements

    where {reportID} is the ID of the report without brackets. You can obtain this by querying https://your-viya-server.com/reports/reports/, or by selecting "Copy Link" in Visual Analytics in the report and copying the report ID from the URL:

    enter image description here

    This report's ID is 1e6c7501-84bd-4949-8045-95d581dd1b38.

    Example of getting a report's contents:

    {
      "links": [
        {
          "method": "GET",
          "rel": "self",
          "href": "/reports/reports/1e6c7501-84bd-4949-8045-95d581dd1b38/content/elements",
          "uri": "/reports/reports/1e6c7501-84bd-4949-8045-95d581dd1b38/content/elements",
          "type": "application/vnd.sas.collection",
          "itemType": "application/vnd.sas.report.content.element"
        },
        {
          "method": "GET",
          "rel": "up",
          "href": "/reports/reports/1e6c7501-84bd-4949-8045-95d581dd1b38",
          "uri": "/reports/reports/1e6c7501-84bd-4949-8045-95d581dd1b38",
          "type": "application/vnd.sas.report"
        }
      ],
      "name": "reportContentElements",
      "accept": "application/vnd.sas.report.content.element",
      "count": "3",
      "items": [
        {
          "name": "vi6",
          "label": "Migration Timeline",
          "type": "Section",
          "version": 1
        },
        {
          "name": "vi357",
          "label": "EG Project Status",
          "type": "HiddenSection",
          "version": 1
        },
        {
          "name": "ve27",
          "label": "Import details for EG projects",
          "type": "Table",
          "version": 1
        }
      ],
      "version": 2
    }
    

    In this case, there are two pages: one standard page (vi6 - Migration Timeline) and one hidden page (vi357 - EG Project Status).