BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10

Under what situations CALL ROUTINE is used over SAS functions such as CALL SCAN vs. SCAN?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

My general rule of thumb is to use the function when possible.  The CALL routines can do more, but the functions can do the most commonly required tasks.  So switch to the CALL routine when you need something a little more complex than what the function can do.  By using the functions when possible, you can use a simpler program at the cost of having slightly less functionality available.

View solution in original post

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

From the documentation:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001131396.htm

 

To try and put it another way, call <function> does something, but doesn't necessarily assign a result.  Lok at the examples in the documentation:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002255934.htm

You will see that call scan is executed, but is not assigned to anything e.g.:

abc=scan(...);

call scan(...);

 

The first example assigns the result to abc, the second just executes the function, no return.

Astounding
PROC Star

My general rule of thumb is to use the function when possible.  The CALL routines can do more, but the functions can do the most commonly required tasks.  So switch to the CALL routine when you need something a little more complex than what the function can do.  By using the functions when possible, you can use a simpler program at the cost of having slightly less functionality available.

Loko
Barite | Level 11

Hello,

 

I pretty much use call missing function when I have to set to missing both character and numeric variables.

 

For example when I use hash and have previously loaded variables using set, I find useful call missing rather then missing.

 

Consider the following example:

 

data want;
if 0 then set have hash1;

if _N_=1 then
    do;
        declare hash a(dataset: "hash1");
        a.definekey('key');
        a.definedata('num1', 'num2', 'num3', 'char1', 'char2', 'char3');
        a.definedone();
    end;

set have;

if a.find() ne 0 then call missing(num1, num2, num3, char1, char2, char3);


run;

 

SAS_inquisitive
Lapis Lazuli | Level 10

Thank you, all.

SAS_inquisitive
Lapis Lazuli | Level 10

I was looking at this example in SAS doc. So CALL SCAN is able to create variables from its arguments (position, length) without specifying those variables explicitly?

 

data artists;
   input string $60.;
   drop string;
   do i=1 to 99;
      call scan(string, i, position, length);
      if not position then leave;
      Name=substrn(string, position, length);
      output;
   end;
   datalines;
Picasso Toulouse-Lautrec Turner "Van Gogh" Velazquez
;

proc print data=artists;
run;

 

 

Tom
Super User Tom
Super User

SAS always creates new variables when you reference a name that it has not seen before.  That has nothing to do with CALL SCAN().

SAS_inquisitive
Lapis Lazuli | Level 10

I looked closely at the arugments of the CALL SCAN. It makes sense now.  

Thanks !

data_null__
Jade | Level 19

This example may further your understanding.  It looks for a string that is all uppercase and 2 bytes long.  Using call scan I find the position and length of each uppercase string.  if length eq 2.  substring the target from p for l.  Using SCAN function you would have to measure the result returned from SCAN.  Same but different.

 

data _2upcase;
   input string $50.;
   do c=1 by 1 until(l eq 2 or p eq 0);
      call scan(strip(string),c,p,l,,'ldsp');
      end;
   length _2upcase $2;
   _2upcase = substrn(string,p,l);
   cards;
nndkd11UUndkdLLL
kdnakaliueoina
nnnlllLLLlllLLlll
thisISa2DIgit
this IS silly
this.IS.silly
;;;;
   run;

I reckon this could be replaced with a one line RegEX but that's another topic.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 4353 views
  • 7 likes
  • 6 in conversation