BookmarkSubscribeRSS Feed
asdfghjkl__lpoi87654ewasxcv
Calcite | Level 5


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?

5 REPLIES 5
Haikuo
Onyx | Level 15

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

asdfghjkl__lpoi87654ewasxcv
Calcite | Level 5

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.

Haikuo
Onyx | Level 15

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

asdfghjkl__lpoi87654ewasxcv
Calcite | Level 5

This will work for what I need: ODS TEXT= Statement

ods text="";

Now just need options for quick style formatting.Smiley Happy

Thanks for the link to the guide.

Quentin
Super User

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.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

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
  • 5 replies
  • 1272 views
  • 6 likes
  • 3 in conversation