The SAS Output Delivery System and reporting techniques

Dividing Char $21. format value by numeric best12. format

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 88
Accepted Solution

Dividing Char $21. format value by numeric best12. format

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.


Accepted Solutions
Solution
‎03-25-2013 07:44 AM
Super User
Posts: 5,257

Re: Dividing Char $21. format value by numeric best12. format

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.

Data never sleeps

View solution in original post


All Replies
Super User
Posts: 5,257

Re: Dividing Char $21. format value by numeric best12. format

You need to input unadjprice into a numeric column, then do the calculation.

Data never sleeps
Frequent Contributor
Posts: 88

Re: Dividing Char $21. format value by numeric best12. format

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.

Solution
‎03-25-2013 07:44 AM
Super User
Posts: 5,257

Re: Dividing Char $21. format value by numeric best12. format

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.

Data never sleeps
Frequent Contributor
Posts: 88

Re: Dividing Char $21. format value by numeric best12. format

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 271 views
  • 0 likes
  • 2 in conversation