DATA Step, Macro, Functions and more

Error in CATT function?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Error in CATT function?

Hi again helpful SAS community!

 

A couple of weeks ago, Reeza was super helpful and helped me create run a macro by pulling ids from a large (10,000) file.

Here's what she suggested - which worked

Data _null_;
Set idlist2;

Str = catt('%tool(', id, ');');
Call execute ( Str);

Run;

However, part of my Macro involved running an x-command, and although I was indeed generating multiple excel spreadsheets, the data within the docs generated were messed up ... I *think* because of timing issues.

 

In any case, what I need now is to parse TWO fields from the IdList dataset into my Macro ... here's what I'm trying (code below), but it doesn't work. 

 

Data _null_;
Set idList;

Str = catt('%tool1(', id, Id2, ');');

Call execute ( Str);
Run;

I think I'm missing something really basic about the "CATT" function that I just can't see.  I hope this is a really basic error - I don't mind looking dumb if I can learn something new!  I hope someone can help me figure this out.

 

thank you so much!


Accepted Solutions
Solution
‎08-18-2016 04:58 PM
Super User
Posts: 17,819

Re: Error in CATT function?

Now you're missing a comma Smiley Happy

 

Put them each on their own line to help. Note the missing comma after the "," in your code. 

 

Str = catt('%tool1(',
id,
","
Id2,
');'
); ---

  

View solution in original post


All Replies
Super User
Posts: 5,256

Re: Error in CATT function?

Perhaps try to put the contents of STR prior to the call execute. And why are you sure that this has to do with the catt function? You need to debug all steps, including the macro.

A LOG would help...

I can't see the macro definition here, but but you may want a comma between id and id2?

Data never sleeps
Occasional Contributor
Posts: 12

Re: Error in CATT function?

Thanks Linus .. I did debug and test the Macro independently; my other responses here should help clarify why I think it's the CATT function.

 

Thanks for helping ...and I love your tag line!

SAS Super FREQ
Posts: 3,476

Re: Error in CATT function?

I'm guessing that you want a comma between your arguments? Maybe

Str = catt('%tool1(', id, ',', Id2, ');');

 

Super User
Posts: 17,819

Re: Error in CATT function?

The string being passed to Call Execute needs to be a valid SAS syntax. Currently it's not. 

 

One way to debug this is to create a dataset and examine the values of STR being created.

 

Data check;
Set idList;

Str = catt('%tool1(', id, Id2, ');');

*Call execute ( Str);
Run;

Open the check dataset and examine the values of STR. If they'renot valid  SAS code, what does it need.

 

Spoiler
You're missing the comma between the two parameters in the macro call. You can add it in the CATT function. It needs to resolve to %tool(id, id2);

Right now it's resolving to the following which is incorrect.

%tool(id id2);
Occasional Contributor
Posts: 12

Re: Error in CATT function?

Thanks everyone. I did use SYMBOLGEN option so I could see how the macro was resolving.

Yeah, I agree, there's a comma missing ... however, when I tried to add one - here's the code & error message:

 

952   Str = catt('%tool1(', id,"," Id2, ');');
                                   ---
                                   22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, /, <, <=,
              <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=,
              |, ||, ~=.

The reason I think I'm just not getting some nuance of CATT is that if I use the old method of concatenating (I'm a dinosaur):

Str2 = '%tool1(' || trim(id) || ',' || trim(IdN) || ');' ;

I get what I need.  I should be content LOL .. but it's bugging me that CATT won't work here.

 

thanks all.

Solution
‎08-18-2016 04:58 PM
Super User
Posts: 17,819

Re: Error in CATT function?

Now you're missing a comma Smiley Happy

 

Put them each on their own line to help. Note the missing comma after the "," in your code. 

 

Str = catt('%tool1(',
id,
","
Id2,
');'
); ---

  

Occasional Contributor
Posts: 12

Re: Error in CATT function?

LOL!!  That's it!!  <DUH!>

 

Sigh ... reminds me of when I first started using SAS 20 years ago and would forget a semi-colon!

I've been away from SAS for 2 years  ... one gets rusty, but it's nice to know this dinosaur can still learn some new tricks!

 

thanks again Reeza, and everyone else here to helped!

 

Love the SAS community!

Super User
Posts: 10,500

Re: Error in CATT function?

Could provide at least an example of the input values and what the catt function is yielding?

Since you have a variable from your data set that we have no idea about the value it is kind of hard to guess.

if that ID variable contains punction such as , or % or & then lots of potential issues.

Occasional Contributor
Posts: 12

Re: Error in CATT function?

Hi Ballardw ... here's a sample of the IDlist .. nothing that should be a problem

 

ID              ID2 
T1-OX3-3007     S3007 
T1-OX3-3010     S3010 
T1-OX3-3081     S3081 
T1-OX3-3083     S3083 
T1-OX3-3087     S3087 


thanks for helping

☑ This topic is SOLVED.

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

Discussion stats
  • 9 replies
  • 376 views
  • 3 likes
  • 5 in conversation