DATA Step, Macro, Functions and more

Display message in editor window

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Display message in editor window

data available  not_available;

merge _temp1 (in=a) _temp2 (in=b); /* One - To - One Join*/

by x;

if a then output available;

if manager = '' then output not_available;

run;

 

in the above code, i am pulling information from _temp2 like manager, project details to _temp1 based on my common variable x.

so dataset "available" will have all the observations coming from _temp1 based on "if" filter. the second dataset "not available" will have observations if my mangager details are missing in "available" dataset.

 

if by chance, if the values are present in "not_available" dataset then sas should stop executing. it should display a message in editor window that "Manager details are missing. Please check". 

 

Please help me on this, is there any way i can pop up messages in editor window


Accepted Solutions
Solution
‎03-25-2017 10:35 AM
Valued Guide
Posts: 505

Re: Display message in editor window

Using an interactive window in 'full' SAS to stop a merge

inspired by
https://goo.gl/JFdCp1
https://communities.sas.com/t5/Base-SAS-Programming/Display-message-in-editor-window/m-p/342380

If manager='' in dataset temp1 then pop up an interactive
window asking the user if he would rather not update
temp1 using temp2

HAVE   TEMP1 and TEMP2
==================================

Up to 40 obs from TEMP1 total obs=4

Obs    KEY    MANAGER    PROJECT    COST

 1      1     Alfred        14      69.0
 2      2     Alice         13      56.5
 3      3                    .        .    Missing in TEMP1
 4      4     Janet         15      62.5



Up to 40 obs TEMP2 total obs=3

Obs    KEY    MANAGER    PROJECT    COST

 1      1                    .        .
 2      2                    .        .
 3      3     Barbara       13      65.3  Manager Present in TEMP2 then stop
 4      4                    .        .


WANT ( if manager is missing in temp1 and is populated in
       temp2 pop up this window

+---------------------------+
| COMMAND ====>              |
|                            |
|       Continue Y/N _       |
|                            |
+---------------------------+

IF 'N' is entered

Up to 40 obs from AVAILABLE total obs=3

                          SAV_
Obs    KEY    MANAGER    MANAGER    PROJECT    COST

 1      1     Alfred     Alfred         .        .
 2      2     Alice      Alice          .        .
 3      3     Barbara                  13      65.3


Up to 40 obs WORK.NOT_AVAILABLE total obs=1

Obs    KEY    MANAGER    PROJECT    COST

 1      3     Barbara       13      65.3

IF 'Y' then

Up to 40 obs from AVAILABLE total obs=4

                          SAV_
Obs    KEY    MANAGER    MANAGER    PROJECT    COST

 1      1     Alfred     Alfred         .        .
 2      2     Alice      Alice          .        .
 3      3     Barbara                  13      65.3
 4      4     Janet      Janet          .        .


NOTE: No observations in data set WORK.NOT_AVAILABLE.

WORKING CODE
============

  if sav_manager='' then do;
       window dsn irow=1 rows=12 color=white
          #3 @10
          "Continue Y/N:" +1 YN $1.;
        display dsn;
  end;

FULL SOLUTION
=============

data available not_available(drop=sav_manager);
  retain key manager;
  retain  yn '_';
  merge temp1(in=a rename=manager=sav_manager) temp2;
  by key;
  if a then do;
      manager=coalescec(sav_manager,manager);
      output available;
  end;
  if sav_manager='' then do;
       window dsn irow=1 rows=12 color=white
          #3 @10
          "Continue Y/N:" +1 YN $1.;
        display dsn;
  end;
  if yn="N" then do;
     manager=coalescec(sav_manager,manager);
     output not_available;
     stop;
  end;
  drop yn;
run;quit;

View solution in original post


All Replies
Super User
Posts: 17,840

Re: Display message in editor window

%Window

Solution
‎03-25-2017 10:35 AM
Valued Guide
Posts: 505

Re: Display message in editor window

Using an interactive window in 'full' SAS to stop a merge

inspired by
https://goo.gl/JFdCp1
https://communities.sas.com/t5/Base-SAS-Programming/Display-message-in-editor-window/m-p/342380

If manager='' in dataset temp1 then pop up an interactive
window asking the user if he would rather not update
temp1 using temp2

HAVE   TEMP1 and TEMP2
==================================

Up to 40 obs from TEMP1 total obs=4

Obs    KEY    MANAGER    PROJECT    COST

 1      1     Alfred        14      69.0
 2      2     Alice         13      56.5
 3      3                    .        .    Missing in TEMP1
 4      4     Janet         15      62.5



Up to 40 obs TEMP2 total obs=3

Obs    KEY    MANAGER    PROJECT    COST

 1      1                    .        .
 2      2                    .        .
 3      3     Barbara       13      65.3  Manager Present in TEMP2 then stop
 4      4                    .        .


WANT ( if manager is missing in temp1 and is populated in
       temp2 pop up this window

+---------------------------+
| COMMAND ====>              |
|                            |
|       Continue Y/N _       |
|                            |
+---------------------------+

IF 'N' is entered

Up to 40 obs from AVAILABLE total obs=3

                          SAV_
Obs    KEY    MANAGER    MANAGER    PROJECT    COST

 1      1     Alfred     Alfred         .        .
 2      2     Alice      Alice          .        .
 3      3     Barbara                  13      65.3


Up to 40 obs WORK.NOT_AVAILABLE total obs=1

Obs    KEY    MANAGER    PROJECT    COST

 1      3     Barbara       13      65.3

IF 'Y' then

Up to 40 obs from AVAILABLE total obs=4

                          SAV_
Obs    KEY    MANAGER    MANAGER    PROJECT    COST

 1      1     Alfred     Alfred         .        .
 2      2     Alice      Alice          .        .
 3      3     Barbara                  13      65.3
 4      4     Janet      Janet          .        .


NOTE: No observations in data set WORK.NOT_AVAILABLE.

WORKING CODE
============

  if sav_manager='' then do;
       window dsn irow=1 rows=12 color=white
          #3 @10
          "Continue Y/N:" +1 YN $1.;
        display dsn;
  end;

FULL SOLUTION
=============

data available not_available(drop=sav_manager);
  retain key manager;
  retain  yn '_';
  merge temp1(in=a rename=manager=sav_manager) temp2;
  by key;
  if a then do;
      manager=coalescec(sav_manager,manager);
      output available;
  end;
  if sav_manager='' then do;
       window dsn irow=1 rows=12 color=white
          #3 @10
          "Continue Y/N:" +1 YN $1.;
        display dsn;
  end;
  if yn="N" then do;
     manager=coalescec(sav_manager,manager);
     output not_available;
     stop;
  end;
  drop yn;
run;quit;

Valued Guide
Posts: 505

Re: Display message in editor window

 

Using an interactive window in 'full' SAS to stop a merge

inspired by
https://goo.gl/JFdCp1
https://communities.sas.com/t5/Base-SAS-Programming/Display-message-in-editor-window/m-p/342380

If manager='' in dataset temp1 then pop up an interactive
window asking the user if he would rather not update
temp1 using temp2

HAVE   TEMP1 and TEMP2
==================================

Up to 40 obs from TEMP1 total obs=4

Obs    KEY    MANAGER    PROJECT    COST

 1      1     Alfred        14      69.0
 2      2     Alice         13      56.5
 3      3                    .        .    Missing in TEMP1
 4      4     Janet         15      62.5



Up to 40 obs TEMP2 total obs=3

Obs    KEY    MANAGER    PROJECT    COST

 1      1                    .        .
 2      2                    .        .
 3      3     Barbara       13      65.3  Manager Present in TEMP2 then stop
 4      4                    .        .


WANT ( if manager is missing in temp1 and is populated in
       temp2 pop up this window

+---------------------------+
| COMMAND ====>              |
|                            |
|       Continue Y/N _       |
|                            |
+---------------------------+

IF 'N' is entered

Up to 40 obs from AVAILABLE total obs=3

                          SAV_
Obs    KEY    MANAGER    MANAGER    PROJECT    COST

 1      1     Alfred     Alfred         .        .
 2      2     Alice      Alice          .        .
 3      3     Barbara                  13      65.3


Up to 40 obs WORK.NOT_AVAILABLE total obs=1

Obs    KEY    MANAGER    PROJECT    COST

 1      3     Barbara       13      65.3

IF 'Y' then

Up to 40 obs from AVAILABLE total obs=4

                          SAV_
Obs    KEY    MANAGER    MANAGER    PROJECT    COST

 1      1     Alfred     Alfred         .        .
 2      2     Alice      Alice          .        .
 3      3     Barbara                  13      65.3
 4      4     Janet      Janet          .        .


NOTE: No observations in data set WORK.NOT_AVAILABLE.

WORKING CODE
============

  if sav_manager='' then do;
       window dsn irow=1 rows=12 color=white
          #3 @10
          "Continue Y/N:" +1 YN $1.;
        display dsn;
  end;

FULL SOLUTION
=============

data available not_available(drop=sav_manager);
  retain key manager;
  retain  yn '_';
  merge temp1(in=a rename=manager=sav_manager) temp2;
  by key;
  if a then do;
      manager=coalescec(sav_manager,manager);
      output available;
  end;
  if sav_manager='' then do;
       window dsn irow=1 rows=12 color=white
          #3 @10
          "Continue Y/N:" +1 YN $1.;
        display dsn;
  end;
  if yn="N" then do;
     manager=coalescec(sav_manager,manager);
     output not_available;
     stop;
  end;
  drop yn;
run;quit;

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 148 views
  • 2 likes
  • 3 in conversation