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

Hello, I am a SAS beginner and encounter a question as follows:

I want to output two tables(parks, monuments) from one dataset, say, pg1.np_summary; While in output table parks I wanna keep variables Reg ParkName DayVisits; in output table monuments I wanna keep variables  Reg.  The following is my programming: 

 

data parks monuments;

set pg1.np_summary;

where type in ('NM','NP');

 

if type='NP' then do;

output parks;

keep  Reg ParkName DayVisits;

end;

else do;

output monuments;

keep  Reg ;

end;

run;

 

However, I found the two output tables end up with having only one variable specified(Reg). May I know how to program that in order to have two output tables with different columns? 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data parks(keep=reg parkname dayvisits) monuments(keep=reg);
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
data parks(keep=reg parkname dayvisits) monuments(keep=reg);
--
Paige Miller
Reeza
Super User

KEEP statements apply to all output data sets on the DATA statement.

KEEP data set options apply to only the data set referenced. 

 

You're using a KEEP statement in the data step but need to use a data set option instead. @PaigeMiller provided the code for that solution. 

 


@Eathonhua wrote:

Hello, I am a SAS beginner and encounter a question as follows:

I want to output two tables(parks, monuments) from one dataset, say, pg1.np_summary; While in output table parks I wanna keep variables Reg ParkName DayVisits; in output table monuments I wanna keep variables  Reg.  The following is my programming: 

 

data parks monuments;

set pg1.np_summary;

where type in ('NM','NP');

 

if type='NP' then do;

output parks;

keep  Reg ParkName DayVisits;

end;

else do;

output monuments;

keep  Reg ;

end;

run;

 

However, I found the two output tables end up with having only one variable specified(Reg). May I know how to program that in order to have two output tables with different columns? 


 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1785 views
  • 4 likes
  • 3 in conversation