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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Now you're missing a comma 🙂

 

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

9 REPLIES 9
LinusH
Tourmaline | Level 20

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
Geetu
Obsidian | Level 7

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!

Rick_SAS
SAS Super FREQ

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

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

 

Reeza
Super User

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);
Geetu
Obsidian | Level 7

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.

Reeza
Super User

Now you're missing a comma 🙂

 

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

 

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

  

Geetu
Obsidian | Level 7

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!

ballardw
Super User

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.

Geetu
Obsidian | Level 7

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

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
  • 9 replies
  • 1900 views
  • 3 likes
  • 5 in conversation