Help using Base SAS procedures

Datasets from specific library and change names in work library

Accepted Solution Solved
Reply
Super Contributor
Posts: 374
Accepted Solution

Datasets from specific library and change names in work library

I'd like call datasets from specific library and change their names in work library. I'm not allowed to change the dataset names permanently because of shared property. I have 30 datasets and will execute the proc datasets in macro once my code works out outside the macro. What am I doing wrong?

 

LIBNAME m "......\work_data";

proc datasets lib=m;
change m.data2015_bf=data_2015; 
run;
quit 

Error log:

 

126 proc datasets lib=m;

127 change m.data2015_bf=data_2015;

----------------

22

201

ERROR 22-322: Expecting a name.

ERROR 201-322: The option is not recognized and will be ignored.

128 run;

NOTE: Enter RUN; to continue or QUIT; to end the procedure.

NOTE: Statements not processed because of errors noted above.

129 quit


Accepted Solutions
Solution
‎11-17-2017 01:03 PM
Super User
Super User
Posts: 9,599

Re: Datasets from specific library and change names in work library

Do you know what I have never even heard of the change operation in proc datasets.  Me I would simply do, as you want to copy them to work and not change them in place - which is where your error happens (I imagine you don't have permission to change them):

data _null_;
  set sashelp.vtable (where=(libname="M"));
  call execute('data '||strip(memname)||'; set m.'||strip(memname)||'; run;');
run;

That will do a datastep to copy each one from M to work, you can also include your rename part there, so you want an underscore:

data _null_;
  set sashelp.vtable (where=(libname="M"));
  call execute('data '||substr(memname,1,4))||'_'||substr(memname,5)||'; set m.'||strip(memname)||'; run;');
run;

 

View solution in original post


All Replies
Solution
‎11-17-2017 01:03 PM
Super User
Super User
Posts: 9,599

Re: Datasets from specific library and change names in work library

Do you know what I have never even heard of the change operation in proc datasets.  Me I would simply do, as you want to copy them to work and not change them in place - which is where your error happens (I imagine you don't have permission to change them):

data _null_;
  set sashelp.vtable (where=(libname="M"));
  call execute('data '||strip(memname)||'; set m.'||strip(memname)||'; run;');
run;

That will do a datastep to copy each one from M to work, you can also include your rename part there, so you want an underscore:

data _null_;
  set sashelp.vtable (where=(libname="M"));
  call execute('data '||substr(memname,1,4))||'_'||substr(memname,5)||'; set m.'||strip(memname)||'; run;');
run;

 

Super User
Posts: 13,583

Re: Datasets from specific library and change names in work library

If you are accessing the same data sets frequently you might be better off making your own permanent library and creating views that reference those data sets. Then when you access the view in your library it will read the "shared" data set and you have the latest data.

 

If you don't want to deal with having different observations at different times of the day then copying them to your work (or other library) could be in an autoexec.sas.

 

 

Super Contributor
Posts: 374

Re: Datasets from specific library and change names in work library

Figured out from RW9's insights and ballardw's suggestion:

I created a copy folder with all datasets and use that as my library=m. And defined generic library after proc and eliminating libname initials in front of the datasets after "change" line did the job. All I have to do now is to put it in the macro and do the same thing for the rest of the 30-40 datasets. Thanks a lot.

 

LIBNAME m "......\work_data";

 

proc datasets lib=m;

change oldname=newname;

run;

quit

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 269 views
  • 2 likes
  • 3 in conversation