Your SAS programs, embedded in web apps and elsewhere

Retrieve <Name> from a parameter constraint

Reply
Occasional Contributor
Posts: 11

Retrieve <Name> from a parameter constraint

Hi,

I have defined the parameter constraints as = pairs. Can anyone tell me how to retrieve the ? Since is defined much more user friendly I would like to use these as part of title/headers of the report. Thanks.
SAS Super FREQ
Posts: 8,868

Re: Retrieve <Name> from a parameter constraint

Hi:
Check out the first program at this web site: [pre]
http://support.sas.com/rnd/itech/doc9/dev_guide/stprocess/input.html [/pre]

In this program, it shows the use of the "name" piece of the name/value pairs in a title statement:
[pre]title "Product Sales for &MONTH, &YEAR";
[/pre]
In this program, &MONTH and &YEAR are the NAMES of the input parameters (without the & in front) -- that means when you defined them as parameters, whatever you put in the SAS Management Console box for "SAS variable name" now becomes the "NAME" of the parameter (or you could do this in EG as well). For example for me to use &MONTH in my title, I had to define an input parameter called MONTH. The VALUE of the parameter comes from the user who sits at the client application and either types in a value or chooses one of the values you have entered in as constraints for your parameter.
As long as your macro variable reference -inside- the stored process corresponds to the NAME (NOT the prompt) you defined when you registered the SP, then every time the stored process runs, whatever was selected at the client will now be displayed in your title or footnote statement. Remember that since input parameters from the stored process are global macro variables by the time they get to SAS, you must use double quotes around your title statement in order for macro resolution to take place.
cynthia
Occasional Contributor
Posts: 11

Re: Retrieve <Name> from a parameter constraint

Posted in reply to Cynthia_sas
Thanks Cynthia for the response. But I am looking for a way to capture what I think you are referring to as prompt or in EG terminology "Display As" value and not the sas variable name.
SAS Super FREQ
Posts: 8,868

Re: Retrieve <Name> from a parameter constraint

Ahhh, I think I understand. Here's how I'm using the terms -- Let's assume an input parameter for Country:[pre]
prompt=Please select a country
SAS Variable Name = COUNTRY
Macro variable usage in program = &COUNTRY
data set var = CUST_CNTRY = 2 char country code
possible constraint values:
Display AS: Resolves to:
United States US
Italy IT
Ireland IR
[/pre]
What you would get if you placed &COUNTRY into a title is 'US' when they select the "Display As" value of 'United States'. And you want to get "United States" in the title???

So, let's assume that your WHERE statement or IF statement has something like this:

WHERE CUST_CNTRY="&COUNTRY";

I'm figuring you may already have a format in place to translate the 2 character country code to a long country name so someplace before your title, you have to translate the short code to the equivalent of the Display As string: [pre]
title "for country = %sysfunc(putc(&country,$cntry.))";
[/pre]

If your variable is numeric, then you have to use the putn function in your call to %sysfunc. There are other ways to do this with macro processing, but SYSFUNC and a format is one of the easier ways (in my opinion).

Is that what you wanted?
cynthia
Occasional Contributor
Posts: 11

Re: Retrieve <Name> from a parameter constraint

Posted in reply to Cynthia_sas
Yes, this is exactly my question. I am using a look-up table approach which is similar to your format catalog solution. But in either case the look-up table or format catalog should be updated every time when the constraint information changes.

I was really hoping for a solution that the stored process will return this value(s) as a macro variable or some other way. Thanks.
SAS Super FREQ
Posts: 8,868

Re: Retrieve <Name> from a parameter constraint

OK...I understand what you mean, now. The "Display As" values are used to build the appropriate prompting interface in whichever client application is running the stored process. Since the client application is not built in the SAS layer, there is no visibility (that I know of) for those "Display As" values in the SAS layer. Formats generally are an efficient way to perform table lookups for label substitution, as described in these papers: [pre]http://www2.sas.com/proceedings/sugi24/Coders/p097-24.pdf
http://www2.sas.com/proceedings/sugi30/002-30.pdf
http://www.bassettconsulting.com/lazy_way.pdfhttp://www.ats.ucla.edu/STAT/sas/library/nesug00/bt3001...
[/pre] so they're worth giving a try. Especially since you can build a SAS format from a data set or table on the fly using the CNTLIN option of PROC FORMAT.
cynthia
SAS Super FREQ
Posts: 304

Re: Retrieve <Name> from a parameter constraint

If you are dead-set against formats, you could try this for the parameter definition:
Prompt: Please select a country

SAS Variable Name: COUNTRY

Display as: Resolves to:
United States US:United States
Italy IT:Italy
Ireland EI:Ireland
Instead of using COUNTRY directly in your SAS code, use these variables:
%let  RETURN_VALUE = %scan(&COUNTRY, 1, :);
%let DISPLAY_VALUE = %scan(&COUNTRY, 2, :);
It's not very elegant, but it should work.

Vince
SAS R&D
Ask a Question
Discussion stats
  • 6 replies
  • 307 views
  • 0 likes
  • 3 in conversation