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

Hi,

 

This works:

 

data class class_cols;
   set sashelp.class;
   output class;
run;

proc ds2;
   data test(overwrite=yes);
      dcl package hash h();
      dcl double num;
      method init();
         if 0 then set class_cols (locktable=share);
         h.definekey('name');
         h.definekey('sex');
         h.definedata('age');
         h.definedata('height');
         h.definedata('weight');
         h.dataset('{select * from class where sex=''F''}');
         h.definedone();
         num=h.num_items;
         put num=;
      end;
   enddata;
   run;
quit;
data test;set test;run;  * to get EG to display the results from DS2 ;

 

But this fails:

 

data class class_cols;
   set sashelp.class;
   output class;
run;

proc ds2;
   data test(overwrite=yes);
      dcl package hash h();
      dcl double num;
      method init();
         if 0 then set class (locktable=share);
         h.definekey('name');
         h.definekey('sex');
         h.definedata('age');
         h.definedata('height');
         h.definedata('weight');
         h.dataset('{select * from class where sex=''F''}');
         h.definedone();
         num=h.num_items;
         put num=;
      end;
   enddata;
   run;
quit;
data test;set test;run;

How do I get this 2nd example to work?  Is there a better way?  This approach is quite common in data step processing.

 

Thanks,

Scott


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Scott

 

I guess you need to set the LOCKTABLE= option on both statements. See also here FedSQL Statement Table Option Syntax

 

See an example below:

 

data class class_cols;
   set sashelp.class;
   output class;
run;

proc ds2;
   data test(overwrite=yes);
      dcl package hash h();
      dcl double num;
      method init();
         if 0 then set class (locktable=share);
         h.definekey('name');
         h.definekey('sex');
         h.definedata('age');
         h.definedata('height');
         h.definedata('weight');
         h.dataset('{select * from class {options LOCKTABLE= SHARE} where sex=''F''}');
         h.definedone();
         num=h.num_items;
         put num=;
      end;
   enddata;
   run;
quit;
data test;set test;run;

Bruno

View solution in original post

5 REPLIES 5
BrunoMueller
SAS Super FREQ

Scott

 

I guess you need to set the LOCKTABLE= option on both statements. See also here FedSQL Statement Table Option Syntax

 

See an example below:

 

data class class_cols;
   set sashelp.class;
   output class;
run;

proc ds2;
   data test(overwrite=yes);
      dcl package hash h();
      dcl double num;
      method init();
         if 0 then set class (locktable=share);
         h.definekey('name');
         h.definekey('sex');
         h.definedata('age');
         h.definedata('height');
         h.definedata('weight');
         h.dataset('{select * from class {options LOCKTABLE= SHARE} where sex=''F''}');
         h.definedone();
         num=h.num_items;
         put num=;
      end;
   enddata;
   run;
quit;
data test;set test;run;

Bruno

ScottBass
Rhodochrosite | Level 12

Thanks that works, although I'm surprised that either the set statement or "select * from class" puts a lock on the table such that the other statement fais :-?


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
BrunoMueller
SAS Super FREQ

Scott

 

I do not know why, since both are read only.

 

bruno

ScottBass
Rhodochrosite | Level 12

Yep, my comment was more for any birdies that care to chime in.  Yes, since SET and SELECT are both readonly, and explicitly supplying LOCKTABLE=SHARE works, why couldn't the underlying code do that, i.e. make both opens of the table "shared"?

 

Rhetorical question, no need to reply, but if any birdies want to chime in...or change the code...feel free 🙂


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
BrunoMueller
SAS Super FREQ

Hi Scott

 

After reading the doc on the LOCKTABLE= table option comes the explantion

 

LOCKTABLE= Table Option

Details
You can lock tables only if you are the owner or have been granted the necessary privilege.
If you use PROC DS2, the default value for the LOCKTABLE option is EXCLUSIVE.

 

Bruno

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!

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
  • 1291 views
  • 1 like
  • 2 in conversation