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.
@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.
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.
can you post your data and code?
@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.
@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.
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".
@PaigeMiller I will, thanks Paige. And sorry!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: