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. 

 

 

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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