I am creating SAS stored processes with prompts for users that do not read SAS code; so I need to provide meaningful feedback to them when something goes wrong that does not involve looking at the log. For example, if they enter a category that does not exist in the dataset I would like to just show an error in the stored proc output that says "selected category does not exist" rather than crashing the program and having to review the log for such a simple mistake. Currently I am doing this by creating a dummy dataset with a single var called 'error' with the value set to the error text string and then printing that dataset, which seems inelegant at best. What is the best way to provide feedback to the user of a stored proc?
The information you gave is vague enough that my suggestion could be completely off. Anyway, for your question, one DIRECT answer could be:
1. First check the query outcome table
2. If null/zero obs /empty, "then put ' selected category does not exist';" in the log or anywhere you want to store/display the message. Else, your process moves on.
I don't have details of your STP, but given the scenario, I would recommend the following INDIRECT approach:
1. Make a view containing all of your distinct categories, and register this view in Metadata.
2. Then you can offer your users to select categories from a pull-down list, without worrying about their entering.
The benefit is obvious: human free text entering is the worst nightmare for data management. The cases, the space, -, ., /\ , misspell and other typos would easily blow up their query. In this case, give your users as little freedom as possible to protect their interest.
Haikuo
Generically speaking I'm looking for solution options for providing feedback to the user in the output rather than the log. What you described in your first scenario is essentially the logic I'm using, but the users don't want to look at the log so they are coming back to me for review. it would be nice if there was a 'put' equivalent that went to the listing/ods destination rather than just the log. In other programming languages outputting to any destination is done via the same methods but I can't find a way to pass a simple text message to the output stream for SAS. I agree that I should avoid user input, but there are other scenarios where this would be useful; say if something failed and the result table is empty, could I just output a message that says the data is not available for that table rather than dumping the entire log.
Quote: "outputting to any destination is done via the same methods",
in SAS, you are looking at SAS(R) 9.3 Output Delivery System: User's Guide, Second Edition
Any destination, many file types.
Quote: " say if something failed and the result table is empty, ",
It will NOT happening using the method I suggest. The whole idea of using a SAS VIEW is to extract realtime information on the fly. If something shows up in the prompt pull-down list, then there is something there, the outcome will NOT empty; otherwise your users will NOT see it in the pull-down list.
The free text searching is useful when your exact intention is to provide free text key word searching.
Message was edited by: haikuo bian
This will work for what I need: ODS TEXT= Statement
ods text="";
Now just need options for quick style formatting.
Thanks for the link to the guide.
You want a PUT statement, you can use a PUT statement....
data _null_ ;
file print ;
put "Thank you for trying, but please try again." ;
run;
If you stored process is writing to _webout or whatever, that should write the message to the output.
In practice, I seem to switch randomly between ODS text=, data _null_ like above, and your mentioned approach of proc reporting a 1-variable 1-record dataset.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.