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 ;
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
Length attributes:
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
Length attributes:
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
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.
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.
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?
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.
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.