Your SAS programs, embedded in web apps and elsewhere

prompt type

Posts: 24

prompt type

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.



Frequent Contributor
Posts: 91

Re: prompt type

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

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">
<Text xml:lang="en-GB">date prompt label</Text>

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.


Ask a Question
Discussion stats
  • 1 reply
  • 1 like
  • 2 in conversation