BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jonatan_velarde
Lapis Lazuli | Level 10

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 toScreenshot from 2019-10-02 09-35-55.png

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

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")

--
Paige Miller
jonatan_velarde
Lapis Lazuli | Level 10
still does not work
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
jonatan_velarde
Lapis Lazuli | Level 10
All variables are numeric
andreas_lds
Jade | Level 19

@jonatan_velarde wrote:
All variables are numeric

The why to do compare with "."? Removing the quotes should help.

andreas_lds
Jade | Level 19

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.

 

Kurt_Bremser
Super User

@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)

Kurt_Bremser
Super User

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.

Kurt_Bremser
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 9 replies
  • 1444 views
  • 2 likes
  • 4 in conversation