BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Neal0801
Obsidian | Level 7
data AXPM061204200; 
set a; 
call execute ("data work.data_"||strip(put(_ric,$13.))||"_"||strip(put(date,yymmddn8.))||"; 
               set work.a;if date="||date||" and _ric="||input(_ric,$13.)||";run;"); 
run;

I have a large dataset that contians multiple date (from 20120103 to 20121205) and contracts (_ric= AXPM061204200.c, AXPC061204200.c and so on).

 

 

I tried to use "call exectue" to split the dataset and here is my code. It can only split by date, but fail in contract name (_ric). The error was : Variable AXPM061203800 is uninitialized. How could I solve this problem.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

A couple hints when working with Call execute.

1) It is often easier to define a long string variable for the argument of Call execute and then use some thing like

        call execute (string);

2) you can use put statements to check the value of the string to see if things look right.

3) use the CAT functions such as CATS or CATX. The venerable || operator often results in undesired spaces leading or trailing bits of your code.

4. Instead of trying to force:

     Data work.data_longnamehere;

          set work.if;

          If date= "some obnoxious value" and _ric="some other value";

      run;

Into a single call execute do something like:

     call execute('Data work.data_longnameconstructhere;');

      call execute('set work.if;');

      call execute('If date= "some obnoxious value" and _ric="some other value";');

      call execute('run;');

You can see in the second bit above that two of the 4 lines don't change so the construction of the "string" variable would be easier.

 

This bit of your code: strip(put(date,yymmddn8.))||";  inicates that DATE is a SAS date valued numeric.

I think: date="||date||" is doing something unnatural for numerics and _ric="||input(_ric,$13.)||" as a comparison should likely fail as a variable with more than 13 characters will never equal the first 13 characters. And what is wrong with substr?

View solution in original post

5 REPLIES 5
Reeza
Super User

If you run it with the following options and examine your log you'll see the exact code that's being created. There's something in the code that's incorrect, but sometimes hard to see in the current format.

 

options mprint symbolgen;

 

Astounding
PROC Star

The code in the IF conditions generates:

 

and _ric=some_value

 

But _RIC is a character variable, so you need quotes in the generated statement:

 

and _ric="some_value"

ballardw
Super User

A couple hints when working with Call execute.

1) It is often easier to define a long string variable for the argument of Call execute and then use some thing like

        call execute (string);

2) you can use put statements to check the value of the string to see if things look right.

3) use the CAT functions such as CATS or CATX. The venerable || operator often results in undesired spaces leading or trailing bits of your code.

4. Instead of trying to force:

     Data work.data_longnamehere;

          set work.if;

          If date= "some obnoxious value" and _ric="some other value";

      run;

Into a single call execute do something like:

     call execute('Data work.data_longnameconstructhere;');

      call execute('set work.if;');

      call execute('If date= "some obnoxious value" and _ric="some other value";');

      call execute('run;');

You can see in the second bit above that two of the 4 lines don't change so the construction of the "string" variable would be easier.

 

This bit of your code: strip(put(date,yymmddn8.))||";  inicates that DATE is a SAS date valued numeric.

I think: date="||date||" is doing something unnatural for numerics and _ric="||input(_ric,$13.)||" as a comparison should likely fail as a variable with more than 13 characters will never equal the first 13 characters. And what is wrong with substr?

ChrisHemedinger
Community Manager

You might also be able to adapt this approach, which doesn't rely on CALL EXECUTE. 

 

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
Neal0801
Obsidian | Level 7

Thanks. I finally figured out the source of the problem. Since _ric is a characteristic variables, I should put extra ' ' to tell SAS that is characteristic variables. 

So my final code is :

 

_ric='"||input(_ric,$13.)||"'

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1324 views
  • 2 likes
  • 5 in conversation