1

is there a way to check if a savedlist is empty in Unidata (and if so generate a new savedlist)?

The pseudo code would essentially be:
IF savedlist1 IS EMPTY
SELECT PERSON SAMPLE 1
SAVE.LIST savedlist1

(if not empty, leave the original savedlist1 as is)

An alternative approach is if a SELECT statement does not return any results, is there a way to prevent a savedlist from being created, like this:

create a savedlist in case nothing is selected for what I actually want
SELECT PERSON SAMPLE 1
SAVE.LIST savedlist1

create the savedlist of what I actually want, if it fails use the one above
SELECT PERSON WITH NAME EQ 'Bruce' REQUIRE.SELECT
SAVE.LIST savedlist1 (IF selection returned results)

I have tried adding REQUIRE.SELECT and SELECT.ONLY, but by the time it gets to the SAVE.LIST command the selection is terminated, and I just get "No active select list, creating empty saved list." Trying to add either to the SAVELIST line results in a syntax error.

The final way I thought to manage this is by appending the select statement to an existing savedlist, but I have not had luck with MERGE.LIST or TO with that:
SELECT PERSON WITH NAME EQ 'Bruce' TO savedlist1
TO can't be used with SELECT/COUNT/SUM/TAPE

Jeremy
  • 23
  • 4

2 Answers2

1

Are you building a paragraph, if yes, you can check for @SYSTEM.RETURN.CODE (please check the manual for exact syntax). It will be -1 if nothing is selected.

Philip
  • 26
  • 1
  • Yes, I am building a paragraph, I am learning from documentation from Rocket's website like the "Unidata Command Reference" or "UniData Using UniQuery" and existing paragraphs that were present on the system when I started. Any other learning material recommendations would be greatly appreciated. Thank you for the information, that worked perfectly! – Jeremy Sep 07 '22 at 15:11
0

Philip's recommendation worked perfectly:

create a savedlist to "Fall Back" on in case nothing is selected for what I actually want:

SELECT PERSON SAMPLE 1  
SAVE.LIST savedlistFallBack

create a savedlist for what I actually want

SELECT PERSON WITH NAME EQ 'Bruce'   
SAVE.LIST savedlist1

if no records were selected (no one was named Bruce) then overwrite the empty savedlist with my "Fall Back" one

IF @SYSTEM.RETURN.CODE LT 0 THEN COPY.LIST savedlistFallBack savedlist1 -O
Dharman
  • 30,962
  • 25
  • 85
  • 135
Jeremy
  • 23
  • 4