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

Hi all,

 

I am struggling to find the product of a negative and a positive number. My data is as below:

 

Product      Year        Variable1       Variable2

1                  2010        0.234              -12345

1                  2011        0.545              -59865

2                  2010        0.896              -56896

2                  2011        0.568              -13899

 

I need to multiply variable 1 and variable 2. How do I deal with this? Would appreciate all your help. Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@PDevi wrote:
@SAS47 I was running this exact same code but it is returning only empty values; hence my struggle. 🙂

When you read the LOG did you see any "invalid data" messages?

 

Or "Variable xxxxxx is unitialized"? That typically means you used a variable name with no values. Which happens when you mean to type "height" but misspell such as "hheight" "heght" or such. SAS will in this case 1) create a variable of the wrong name and 2) assign missing values to it and almost any calculation using that misspelled name.

 

View solution in original post

8 REPLIES 8
SAS47
Calcite | Level 5

Hi,
You can use assignment statement to multiply the two variables.

Refer to documentation below.
https://documentation.sas.com/doc/en/pgmsascdc/v_014/ds2ref/n1eexsj5t1lpn3n1bflloua85i1p.htm

 

You can use he code below.

data abc_mult; */creates a temporray data /*
set abc; */Read your data/*
var_prod=Variable1*Variable2; */Assignment Statement to multiply two variables/*
run;

This assignment statement will help you to multiply positive and negative variable as well.


PDevi
Fluorite | Level 6
@SAS47 I was running this exact same code but it is returning only empty values; hence my struggle. 🙂
PaigeMiller
Diamond | Level 26

@PDevi wrote:
@SAS47 I was running this exact same code but it is returning only empty values; hence my struggle. 🙂

Show us the actual LOG for this data step, all of it, every single line, do not chop out parts of the log for this data step. Also, show us the results.

--
Paige Miller
tarheel13
Rhodochrosite | Level 12

can you post your data and code? 

ballardw
Super User

@PDevi wrote:
@SAS47 I was running this exact same code but it is returning only empty values; hence my struggle. 🙂

When you read the LOG did you see any "invalid data" messages?

 

Or "Variable xxxxxx is unitialized"? That typically means you used a variable name with no values. Which happens when you mean to type "height" but misspell such as "hheight" "heght" or such. SAS will in this case 1) create a variable of the wrong name and 2) assign missing values to it and almost any calculation using that misspelled name.

 

PDevi
Fluorite | Level 6

@ballardw that was exactly the issue. I had made a very stupid mistake, the label and variable names were slightly different and that was causing this whole issue. Feeling very stupid right now. 😞 

Thanks for your help and time.

PaigeMiller
Diamond | Level 26

This is why we always ask to see the log, when the code isn't working right. From now on, please show us the log when the code isn't working, and you will then get faster and better answers.

 

Also, this is why "Read the Log" has risen to number 2 in the "Maxims of Maximally Efficient SAS Programmers".

 

 

--
Paige Miller
PDevi
Fluorite | Level 6

@PaigeMiller I will, thanks Paige. And sorry! 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1588 views
  • 3 likes
  • 5 in conversation