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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

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

4 REPLIES 4
LinusH
Tourmaline | Level 20

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

Data never sleeps
Tushar
Obsidian | Level 7

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.

LinusH
Tourmaline | Level 20

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
Tushar
Obsidian | Level 7

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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