Help using Base SAS procedures

PROC export with a KEEP statement

Reply
Super Contributor
Posts: 279

PROC export with a KEEP statement

Can I make this code work somehow? The starred out keep option doesn't work but I want it to. Smiley Happy I could create a another data step with just these variables but am always looking for more efficient means of doing things.

proc export data=astu_efa_sort /*(keep=(schnum permnum_s last_s first_s middle_s grade_s efaprim engprof_s advisor_s ela_sort math_sort science_sort social_sort))*/
outfile='G:\Departments\Research\TESTING\PASS\2009\TestingRosters\prelim_roster' dbms=excel replace;
run;
Respected Advisor
Posts: 3,799

Re: PROC export with a KEEP statement

With PROC EXPORT the best you can do is to create a VIEW with the subset of variables you want. Should be efficient enough.
Super Contributor
Posts: 281

Re: PROC export with a KEEP statement

I have no problems getting proc export to work with a keep statement in SAS 9.2.

your syntax is wrong, there is no parenthesis after keep=, and thus you would also only need a single parenthesis at the end of the keep list
Super Contributor
Posts: 279

Re: PROC export with a KEEP statement

Thanks. When I removed a set of ( ), it worked, BUT I had to star out the WHERE statement. Should I not be able to to get the WHERE and KEEP statement to work?

option spool;
proc export data=astu_efa_sort /*(where=(schnum='006'))*/

(keep=schnum permnum_s last_s first_s middle_s grade_s efaprim engprof_s advisor_s ela_sort math_sort science_sort social_sort)

outfile='G:\Departments\Research\TESTING\PASS\2010\TestingRosters\prelim_roster.xls'
dbms=excel
replace;
run;
Regular Contributor
Posts: 165

Re: PROC export with a KEEP statement

Are you putting the where and keep inside of one parenthesis or two? ie.
(where=(schnum='006') keep=schnum permnum_s last_s first_s middle_s grade_s efaprim engprof_s advisor_s ela_sort math_sort science_sort social_sort)

or
(where=(schnum='006')) (keep=schnum permnum_s last_s first_s middle_s grade_s efaprim engprof_s advisor_s ela_sort math_sort science_sort social_sort)

it is more helpful to see the code when it failed (and preferably in the log) than when things are comented out so it doesn't fail.
Super Contributor
Posts: 279

Re: PROC export with a KEEP statement

Here is the failed code:

proc export data=astu_efa_sort (where=(schnum='006'))
(keep=schnum permnum_s last_s first_s middle_s grade_s efaprim engprof_s advisor_s ela_sort math_sort science_sort social_sort)
outfile='G:\Departments\Research\TESTING\PASS\2010\TestingRosters\prelim_roster.xls'
dbms=excel
replace;
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: PROC export with a KEEP statement

Your KEEP= and WHERE= both must be located inside a set of parentheses for the particular dataset being referenced.

Scott Barry
SBBWorks, Inc.
Regular Contributor
Posts: 165

Re: PROC export with a KEEP statement

the where and keep options should be inside one set of parenthesis. See the following:

http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001000998.htm
Ask a Question
Discussion stats
  • 7 replies
  • 7184 views
  • 0 likes
  • 5 in conversation