BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Kelly_K
Fluorite | Level 6

Hi, SAS Community.

I'm trying to subset a dataset so that it includes only those observations that have the variable "year" coded as 2008, but either nothing happens or my output data table is devoid of observations for all variables.  

My data looks something like this:

id      var1       var2     var3          year

1         25          38        yes          2008

2         16          72        yes          2016

3          3           51         no           2008

4         12          16        yes          2016

etc.

 

The following code creates a dataset with all variable columns but no values:

data subset;
set dataset;
where year=2008;
run;

 

The following code creates a dataset with no observations deleted (i.e., dataset = subset):

data subset;
set dataset;
if year=2016 then delete;
run;
 
I've even tried convoluted code, like the one below, but it also results in an empty data table (i.e., no values in any of the columns):
 
proc sort data=dataset(where=(year=2008)) out=subset;
by id;
run;
 
Does anyone know what's going on?  Google is definitely not being my friend in this instance.
 
Thanks.
1 ACCEPTED SOLUTION

Accepted Solutions
Kelly_K
Fluorite | Level 6

Data is proprietary and I don't feel comfortable sharing it, which is why I posed the question the way I did.  In any event, the problem has been solved.  I thought I had indicated that.  Thanks.  

View solution in original post

5 REPLIES 5
sbxkoenk
SAS Super FREQ

Give us the LOG !

Probably year is a character variable (or something else that should be obvious from the LOG).

Koen

HB
Barite | Level 11 HB
Barite | Level 11
Yes. It doesn't matter now but I would have wagered on
where year='2008';
PaigeMiller
Diamond | Level 26

Probably, it would help to see the log, as said by @sbxkoenk . And we need to see the ENTIRE log for you DATA step, not portions, not the errors only, ALL OF IT for this DATA step.

 

My data looks something like this:

 

But you can help yourself @Kelly_K get faster and better answers, and help us help you, by providing us your exact data (or a portion of it), rather than "... something like this". You need to provide (a portion of) your data as working SAS data step code, emphasis on working, which you can type in yourself or follow these instructions. This should be standard operating procedure, in this thread, and from now on whenever you post a question here.

--
Paige Miller
Kelly_K
Fluorite | Level 6

Data is proprietary and I don't feel comfortable sharing it, which is why I posed the question the way I did.  In any event, the problem has been solved.  I thought I had indicated that.  Thanks.  

PaigeMiller
Diamond | Level 26

@Kelly_K Then please post fake data with fake variable names which has the exact same data set structure as the real data. Post it as WORKING data step code. We will consistently ask you to provide data in that format, so please just go ahead and provide data in that format from now on. You will be helping us, which helps you.

--
Paige Miller

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
  • 5 replies
  • 763 views
  • 1 like
  • 4 in conversation