Good day friends:
I am using some if statements to compare data between 2 lines and put it in a third one, as follows:
data want;
set have;
if A = B then B = C;
if A > 0 and B = "." then C = A;
if B > 0 and A = "." then C = B;
RUN;
But, when i open the result, SAS seem to do not recognize as same values, i am attaching the picture to you to see that SAS is not recognizing it as the same.
My hypothesis is that the values in line A and B are not similar, or 1 of them is considered as character and not numeric, could you help me to solve it please?
thank you .
Is thete any code to
Two numerical values that are visually the same do not have to be that in reality. Calculations can cause very small differences because of the way computers store fractional numbers, and how that is influenced by the sequence of calculations.
So if the numbers are visually the same, apply rounding to make them same:
data want;
set have;
a = round(a,.1);
b = round(b,.1);
if A = B then B = C;
if A > 0 and B = . then C = A;
if B > 0 and A = . then C = B;
run;
Note use of the correct symbol for missing numeric values. "." is a character value.
If A and B are numeric variables (and not character variables), then remove the quotes or double-quotes from your code.
If you are not sure whether they are numeric or character, please run PROC CONTENTS on your data set HAVE.
Some of us will not (or cannot) open Microsoft Office documents, as they are a security risk. In the future, it would be better if you included the graphic or screen capture that you want us to see directly in your reply, via clicking on the "Photos" icon when you type your reply (even though technically, you don't really have a "photo" as George Eastman would recognize the term "photo")
What does PROC CONTENTS say about whether these variables are numeric or character?
Show us the LOG of your code, including the code and any ERROR message. Please maintain the formatting of the log by clicking on the {i} icon and pasting the log into that window — do not skip this step.
@jonatan_velarde wrote:
All variables are numeric
The why to do compare with "."? Removing the quotes should help.
Please post the log as text using the window opening by clicking on the {i}-button to preserve formatting. Screenshots are best added by using the "Photos"-Icon. Attaching office-files is almost always not helpful at all, because many users won't open those files, due to security restrictions.
@andreas_lds wrote:
Please post the log as text using the window opening by clicking on the {i}-button to preserve formatting. Screenshots are best added by using the "Photos"-Icon. Attaching office-files is almost always not helpful at all, because many users won't open those files, due to security restrictions.
And word processors will invariably mangle text up to being unusable (UTF, special symbols like curly quotes etc)
Two numerical values that are visually the same do not have to be that in reality. Calculations can cause very small differences because of the way computers store fractional numbers, and how that is influenced by the sequence of calculations.
So if the numbers are visually the same, apply rounding to make them same:
data want;
set have;
a = round(a,.1);
b = round(b,.1);
if A = B then B = C;
if A > 0 and B = . then C = A;
if B > 0 and A = . then C = B;
run;
Note use of the correct symbol for missing numeric values. "." is a character value.
PS if you want to give us data for testing, supply it in usable form, in a data step with datalines. This way we can create an exact copy of your dataset with copy/paste and submit.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.