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

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

1 ACCEPTED SOLUTION

Accepted Solutions
rogerjdeangelis
Barite | Level 11
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

3 REPLIES 3
rogerjdeangelis
Barite | Level 11
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;

rogerjdeangelis
Barite | Level 11

 

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;

 

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
  • 3 replies
  • 1713 views
  • 2 likes
  • 3 in conversation