Hi All,
I need your help to resolve this issue which i am having regarding base SAS. I have two dataset named 1)totalmergenodup_addmcap_3 and 2) fo_new. The totalmergenodup_addmcap_3 is having variable Unadjprice with below details,
# Variable Type Len Format Informat Label Value
==============================================================================
30 UNADJPRICE Char 21 $21. $21. Unadjprice 57.83
in second dataset, i have variable Networth with below details,
# Variable Type Len Format Informat Label Value
===============================================================================
21 NETWORTH Num 8 BEST12. Networth 69.15
now i want to calculate PbyB (a new variable), so i want something like that PbyB=Unadjprice/Networth. i want this new variable added in totalmergenodup_addmcap_3 dataset with calculated value, how can i do that?
i know maybe its having very simple logic but below things which i have tried and i didn't get value, i am getting only missing value for new variable PbyB.
since i want to calculate pbyb i tried to use put and input function to convert either of the variable in Char or in Numeric and calculated, but i got missing
second i have a tried to use Divide function hoping something i am doing wrong with put and input, it still didn't work.
then i thought maybe its regarding to formating so i used proc dataset with format statement to remove format and create new, still didn't work. Please give me explanation with the code if anyone able to do that, i know it's must be having some easy way but just want to figure out what i am doing wrong.
Thanks a Lot Guys in advanced for your unending Support.
Regards,
Tushar Jagtap.
It helps showing the error, this will be a guessing game otherwise...
My guess: best12. - but you column is defined as $21....?
If just one value in your data does not contain valid numerical data (including missing), there will be a note about invalid numeric data. You can use the ?? operator with input function if this is a expected behavior.
Then it seems you are trying to rename a back to unadjprice, but the char version of unadjprice is still there, and then there is a naming conflict.
You need to input unadjprice into a numeric column, then do the calculation.
Hi LinusH,
If you mean first i need to convert char to numeric unadjprice variable then i have done that,
like
data totalmergenodup_addmcap_3(rename=(a=UNADJPRICE)) ;
set totalmergenodup_addmcap_3 fo_new;
a=input(UNADJPRICE,BEST12.);
PbyB=a/Networth;
run;
I have tried this, but still PbyB variable is showing missing and same statement in the log. If possible can you showe me the code you tried incase?
Regards,
tushar.
It helps showing the error, this will be a guessing game otherwise...
My guess: best12. - but you column is defined as $21....?
If just one value in your data does not contain valid numerical data (including missing), there will be a note about invalid numeric data. You can use the ?? operator with input function if this is a expected behavior.
Then it seems you are trying to rename a back to unadjprice, but the char version of unadjprice is still there, and then there is a naming conflict.
Hello LinusH,
you were right, UNADJPRICE variable had around 25000 observation and when check for missing, it contain some missing value and thats why it was not allowing to perform division, i mean showing missing for all. Thanks again. I will keep in mind this thing that whenever performing any data step calculation need to take care of missing value.
Regards,
Tushar.
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: