BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pink_poodle
Barite | Level 11

PROC FSEDIT is a product of SAS/FSP software for full-screen interactive data entry. This procedure provides a user-friendly interface for entering new and updating old observations in a dataset. 

 

The data entry screen invoked by PROC FSEDIT can be modified using the SCL, SAS Component Language for developing interactive SAS applications. 

 

SCL code consists of parts with headings followed by semicolons (e.g., init:, main:, term: ) that run at different time points of screen appearance, existence and termination, respectively. 

 

Error checking can happen during these stages, depending on the error, but most commonly in the main: section.

 

Now, the question:

 

How can I use SCL to modify the behavior of PROC FSEDIT screen so that it 1) checks if a user is entering a duplicate id (that is already in the dataset), 2) outputs an error message about it and 3) prevents updating the dataset with entries that have duplicate id values?

 

array a 10 { 1 2 3 4 5 6 7 8 9 10 };

fseinit:
control ALLCMDS;
return; init:
if id EQ '' then do; CURSOR id; end; else do; if input(id, 2.) in a then put 'ID is in array a.'; else put 'ID is not in array a.'; protect id; end;
return; main: erroroff _ALL_; if id EQ ' ' then do; erroron id; _msg_ = 'ERROR: EMPTY ID FIELD'; return; end ; cmd = upcase(lastcmd()); if (cmd EQ 'ADD') then do; UNPROTECT id; _msg_ = 'NO DUPLICATE IDS, PLEASE'; end;
return; term: return;

  

1 ACCEPTED SOLUTION

Accepted Solutions
gregl_sas
SAS Employee

Here is one way to check for duplicate values, display a message to the user if they enter a duplicate, and also prevent them from leaving the observation when a duplicate value is present in the field being checked for duplicates.  I am using a copy of the SASHELP.CLASS table, and the NAME column for this example.  You could use a numeric column, but this would require changing the SEARCHC function to SEARCHN.  At this point, this example considers uppercase and lowercase letters as different values.  So you would be able to enter the following names as unique values:  Jane, JANE, jane.

/* FSEINIT executes once when the screen is first opened */
/* create an SCL list with text to display in a messagebox */
FSEINIT:
   msglist=makelist();
   rc=insertc(msglist,'The NAME entered is not unique for in the table',-1);
   rc=insertc(msglist,'Please enter a unique NAME',-1);
return;

/* INIT executes when you access a different observation in the table */
/* fill an SCL list with the unique values of a column in the table
that will be used to check newly entery values against */
INIT:
   dsid=open('sashelp.class');
   namelist=makelist();
   n=0;
   rc=lvarlevel(dsid,'name',n,namelist);
   dsid=close(dsid);
return;

/* MAIN executes when there are actions on the screen - typically when you
press the ENTER key, but this can be modified using the CONTROL statement.  I like to isolate validation by executing it when something changes. In This case, when the NAME field is modified on the screen. There is no need to check for duplicate NAME values if the NAME field is not modified.  If the field is identified as a duplicate, I set the ERROR condition, and the user will not be able to leave the observation until they change the
value, or CANCEL the edit*/
MAIN:
   erroroff _all_;

   if modified(name) then
   do;
       if searchc(namelist,name) > 0 then
       do;
          erroron name;
          text=messagebox(msglist,'S','O');
          cursor name;
       end;
   end;
return;

/* TERM executes when you leave the observation that you are currently
viewing. I delete the NAMELIST that will be recreated when you
access a new observation */
TERM:
   rc=dellist(namelist);
return;

 

View solution in original post

1 REPLY 1
gregl_sas
SAS Employee

Here is one way to check for duplicate values, display a message to the user if they enter a duplicate, and also prevent them from leaving the observation when a duplicate value is present in the field being checked for duplicates.  I am using a copy of the SASHELP.CLASS table, and the NAME column for this example.  You could use a numeric column, but this would require changing the SEARCHC function to SEARCHN.  At this point, this example considers uppercase and lowercase letters as different values.  So you would be able to enter the following names as unique values:  Jane, JANE, jane.

/* FSEINIT executes once when the screen is first opened */
/* create an SCL list with text to display in a messagebox */
FSEINIT:
   msglist=makelist();
   rc=insertc(msglist,'The NAME entered is not unique for in the table',-1);
   rc=insertc(msglist,'Please enter a unique NAME',-1);
return;

/* INIT executes when you access a different observation in the table */
/* fill an SCL list with the unique values of a column in the table
that will be used to check newly entery values against */
INIT:
   dsid=open('sashelp.class');
   namelist=makelist();
   n=0;
   rc=lvarlevel(dsid,'name',n,namelist);
   dsid=close(dsid);
return;

/* MAIN executes when there are actions on the screen - typically when you
press the ENTER key, but this can be modified using the CONTROL statement.  I like to isolate validation by executing it when something changes. In This case, when the NAME field is modified on the screen. There is no need to check for duplicate NAME values if the NAME field is not modified.  If the field is identified as a duplicate, I set the ERROR condition, and the user will not be able to leave the observation until they change the
value, or CANCEL the edit*/
MAIN:
   erroroff _all_;

   if modified(name) then
   do;
       if searchc(namelist,name) > 0 then
       do;
          erroron name;
          text=messagebox(msglist,'S','O');
          cursor name;
       end;
   end;
return;

/* TERM executes when you leave the observation that you are currently
viewing. I delete the NAMELIST that will be recreated when you
access a new observation */
TERM:
   rc=dellist(namelist);
return;

 

SAS Innovate 2025: Register Now

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1041 views
  • 1 like
  • 2 in conversation