BookmarkSubscribeRSS Feed
Alexsander
Fluorite | Level 6

Hi All,

    I need to find the prompt type (eg:character, numeric, date, etc.) through code. I think there should be a way to find the prompt type through metadata functions. not sure how!.

The reason fof this is that While passing prompt value to the browser I need to handle the prmopt values differently based on prompt type.

It would be great if you help me to find the prompt type through code. Thanking you in advance.

Regards,

|alex|

2 REPLIES 2
boemskats
Lapis Lazuli | Level 10

Hi Alex,

Your question got me curious, so I did a bit of digging around metadata and this is how I'd program it. It should be straightforward to do, maybe a little time consuming depending on how/where you're looking at including it.

For prompts, metadata objects are created at the 'Prompt Group' level, and all the prompts within that group are stored as an xml-encoded 'GroupInfo' property of the Prompt Group metadata object. The exception to these are shared prompts which get their own Metadata object, and are pulled in to the prompt group via the 'ReferencedPrompts' property of the PrompGroup object. The properties/definition for that shared prompt are then stored inside a PromptInfo property of the Prompt object, where a TextDefinition/IntegerDefinition/DateDefinition is again stored as an xml-encoded property.

So, to find information on all prompts associated to, say, a stored process, you would need to traverse as follows:

+-> for each ClassifierMap ID

     +-> for each PromptGroup ID (retrieved from the parent ClassifierMap's Prompts property)

       +-> xml-decode GroupInfo property of PromptGroup object and iterate through elements

            -> see structure of the GroupInfo object below

       +-> for each look up any shared prompts by retrieving their ID from the Prompt object found under the ReferencedPrompts property of the PromptGroup

            -> see relevant properties of the shared prompt's Prompt metadata object below

For your reference this is what the decoded PromptGroup object for a typical GroupInfo property of a PromptGroup metadata object looks like. Note the TextDefinitions, IntegerDefinitions, DateDefinitions etc.

<PromptGroup promptId="PromptGroup_123123123123_123123" version="1.0">
  
<DefinitionsAndSubgroups>
  
<TextDefinition macroVarListDelimiter="," macroVarListQuote="&quot;" macroVarOutputLevel="2" minValueCount="0" name="myTextPrompt" promptId="PromptDef_123123123123_123123">
       
<Label>
       
<Text xml:lang="en-US">text prompt label</Text>
       
</Label>
       
<DefaultValue>
            
<String value="DefaultValue" />
       
</DefaultValue>
  
</TextDefinition>
  
<IntegerDefinition name="myNumericPrompt" promptId="PromptDef_123123123123_123123">
       
<Label>
            
<Text xml:lang="en-GB">numeric prompt label</Text>
       
</Label>
  
</IntegerDefinition>
  
<DateDefinition name="dates" promptId="PromptDef_123123123123_123123">
       
<Label>
           
<Text xml:lang="en-GB">date prompt label</Text>
       
</Label>
  
</DateDefinition>
  
</DefinitionsAndSubgroups>
  
<Label>
  
<Text xml:lang="en-US">Label for prompt group</Text>
  
</Label>
</PromptGroup>

And these are the prompt properties you'll be able to retrieve from the PromptInfo xml-encoded property of the shared prompts metadata object:

 

   <DateDefinition name="dates" promptId="PromptDef_123123123123_123123">
       
<Label>
           
<Text xml:lang="en-GB">date prompt label</Text>
       
</Label>
  
</DateDefinition>

You can see these are defined in the same way as the DefinitionAndSubgroups property of the PromptGroup object. Unfortunately prompts seem to be defined using XML at a lower level than standard metadata, so you're going to have to do a bit of work pulling properties out of metadata objects, decoding them, creating a couple of maps using the XML Mapper and iteratively retrieving the spec that way. It should be easily possible, it's just a case of evaluating whether it's worth putting the time in.

In terms of programming the above, you can use the metadata_getnobj function to iterate through each of your stored processes, use metadata_getnprp to iterate through each associated PromptGroup in the ReferencedPrompts property, and then for each of these PromptGroups use metadata_getprop to pull out the GroupInfo object to decode the standard prompt xml definition as above, or the metadata_getnprp function to pull out the ids of each shared prompt and then for each of these again use metadata_getprop to pull out the PromptInfo xml-encoded text as above, decode it, xml-map it and pull out the info you need.

Hope this helps.

Nik

max7
Fluorite | Level 6

Hi Nik,

I have a similar requirement and trying to extract all the prompts associated with stored processes. tried using the proc metadata procedure and able to get the details (including Groupinfo) in the xml form. However I am unable to decode the xml-coded text completely as my 'Groupinfo' property contains values greater than 32767 bytes length. The same issue happens when we use the metadata datastep functions as well as sas datastep only supports 32767b character length. Is there any options in XML mapping which accomadates mapping of longer attribute values(>32767). Or any other work arounds?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1315 views
  • 1 like
  • 3 in conversation