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

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 ;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

5 REPLIES 5
Reeza
Super User

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...

 

 

ManitobaMoose
Quartz | Level 8

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

Reeza
Super User

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.

ManitobaMoose
Quartz | Level 8

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.

Reeza
Super User

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?

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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