DATA Step, Macro, Functions and more

Select Statement is giving me strange numbers

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 130
Accepted Solution

Select Statement is giving me strange numbers

Hi,

 

I am new to SAS programming and am learning from "Learning SAS by Example".

One of the concepts I am looking at is the Select Statement. To my surprise, when I run the statement below, instead of getting numbers of Weight of 1.,5, 1.7, or 2.0, for North, South, and West and East  for each data point by Region, I am only getting a Weight reading for 'South' data, and the number I am getting is 1.69995117, not 1.7. Maybe someone can give me an explanation for this because I have explored all options and do not see why I am getting this result. Thanks a lot!

===========================================

Libname SASData '/folders/myfolders/SASData' ;
Data RegSales ;
    Set SasDATA.Sales ;
    length Weight 3 ;
    Select (Region) ;
        when ('North') Weight = 1.5 ;
        when ('South') Weight = 1.7 ;
        when ('West', 'East') Weight = 2.0 ;
        otherwise Weight = 0 ;
    End ;
run ;


Accepted Solutions
Solution
‎08-23-2017 12:42 PM
Super User
Posts: 23,987

Re: Select Statement is giving me strange numbers

Posted in reply to ManitobaMoose

It works fine for me. The 1.6999 has to do with your LENGTH statement.

Typically a length of 8 is needed for a number. I think you're thinking of length as the number of characters but that's not how it works, it's the number of bytes. 

 

Numerical Accuracy in SAS

http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t...

 

Length attributes:

http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#n08fs0rt7fikeln1uh0t...

 

 

View solution in original post


All Replies
Solution
‎08-23-2017 12:42 PM
Super User
Posts: 23,987

Re: Select Statement is giving me strange numbers

Posted in reply to ManitobaMoose

It works fine for me. The 1.6999 has to do with your LENGTH statement.

Typically a length of 8 is needed for a number. I think you're thinking of length as the number of characters but that's not how it works, it's the number of bytes. 

 

Numerical Accuracy in SAS

http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t...

 

Length attributes:

http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#n08fs0rt7fikeln1uh0t...

 

 

Frequent Contributor
Posts: 130

Re: Select Statement is giving me strange numbers

Hi,

 

Thank you for your reply.

 

The length statement completely makes sense. Thanks. What I still don't understand is why only the 'South' region weight is showing in the Output window, and not the weights for the other regions. If I can figure that out then I will be completely good to go.

 

Thanks for your help!

~Moose

Super User
Posts: 23,987

Re: Select Statement is giving me strange numbers

Posted in reply to ManitobaMoose

That's not what I get when I run the same code. 

Did a previous step modify the SALES data set? Verify the input data set is correct. 

If there's still an issue, post your full code and log.

Frequent Contributor
Posts: 130

Re: Select Statement is giving me strange numbers

I see. I am getting only Weights for South in the Output Window, but when I proc print I get the correct weights in the results window. I guess everything is OK.

Super User
Posts: 23,987

Re: Select Statement is giving me strange numbers

Posted in reply to ManitobaMoose

Because you're creating a data set you shouldn't be seeing anything in the OUTPUT window. 

When you open the data set using the table viewer or proc print do you see the correct results? If so then everything is ok. 

 

Is it possible you're seeing output from a previous procedure?

 

 

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 93 views
  • 2 likes
  • 2 in conversation