DATA Step, Macro, Functions and more

Confused: Why SAS fail to select a row by condition...

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

Confused: Why SAS fail to select a row by condition...

Hi I need some help to figure out this puzzle, I am QAing my own work, and found an error:

 

 

I have this dataset called , with a calculated column called 'week', which, from both proc freq and my eye ball checking, has values from 0 -41.But, I try to print out some extreme values, like 41, log keeps telling me 'no rows were selected'.....

 

proc freq data=numerator2_full;

tables week;

run;

 

 

a.PNG

 

 

b.PNG

 

c.PNG

 

d.PNG

 

I know this probably looks very stupid, but this has drive me crazy....

 

Thank you for your help!


Accepted Solutions
Solution
‎11-01-2017 07:39 PM
Super User
Super User
Posts: 7,928

Re: Confused: Why SAS fail to select a row by condition...

Posted in reply to LisaYIN9309

Perhaps it is not exactly 41?

where round(week,1)=41 ;

Or perhaps you have a format attached?

data want;
 set have ;
 if strip(vvalue(week))='41';
run;

View solution in original post


All Replies
PROC Star
Posts: 8,142

Re: Confused: Why SAS fail to select a row by condition...

Posted in reply to LisaYIN9309

Please post you full log, i.e., including the part where you ran the proc freq.

 

Art, CEO, AnalystFinder.com

 

Solution
‎11-01-2017 07:39 PM
Super User
Super User
Posts: 7,928

Re: Confused: Why SAS fail to select a row by condition...

Posted in reply to LisaYIN9309

Perhaps it is not exactly 41?

where round(week,1)=41 ;

Or perhaps you have a format attached?

data want;
 set have ;
 if strip(vvalue(week))='41';
run;
Contributor
Posts: 36

Re: Confused: Why SAS fail to select a row by condition...

good point @Tom, this week variable is calculated. I calculated as (Vaccine_Day - Pre_day)/7 = week format 8.0

Now I am curious to see how my 

Super User
Posts: 23,224

Re: Confused: Why SAS fail to select a row by condition...

Posted in reply to LisaYIN9309

Ah, yes, you definitely have decimal points then. If you want it actually rounded then round the value.

 

round((Vaccine_Day - Pre_day)/7, 1) format = 8.0

Super User
Posts: 23,224

Re: Confused: Why SAS fail to select a row by condition...

Posted in reply to LisaYIN9309

Run a PROC CONTENTS on your dataset and check the format and type. 

Frequent Contributor
Posts: 113

Re: Confused: Why SAS fail to select a row by condition...

Posted in reply to LisaYIN9309

How did you calculate the variable WEEK?

Contributor
Posts: 36

Re: Confused: Why SAS fail to select a row by condition...

Posted in reply to ShiroAmada
I calculated as (Vaccine_Day - Pre_start_day)/7 = week format 8.0

week is supposed to be 'at which week at pregnant a lady got her vaccine'.

Super User
Super User
Posts: 7,928

Re: Confused: Why SAS fail to select a row by condition...

Posted in reply to LisaYIN9309

LisaYIN9309 wrote:
I calculated as (Vaccine_Day - Pre_start_day)/7 = week format 8.0

week is supposed to be 'at which week at pregnant a lady got her vaccine'.


Attaching a format to a variable will change how the variable is printed, but it does not change the value. If you want WEEK to be an integer then use ROUND() or INT() function.

 

I am also curious as to why you picked 8.0 as the format to attach.  Did you really expect to have WEEK counts as high as 99 Million?

Frequent Contributor
Posts: 113

Re: Confused: Why SAS fail to select a row by condition...

Posted in reply to LisaYIN9309

you can try using int(week)=41, that should help.

☑ This topic is solved.

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

Discussion stats
  • 9 replies
  • 157 views
  • 4 likes
  • 5 in conversation