i want to change variable MSRP which is in char format to numeric type but i dont know how to do it.
any help with complete syntex .
my code is :-
data cars1;
set work.cars;
input MSRP 10.;
fmtMSRP=input(MSRP,comma10.);
run;
here the data set was cars where my MSRP is in char format but i wish to convert it into numeric format.
You can use INPUT either with INFILE or as a function.
To convert the char type to numeric you need a mid name:
data cars1;
set work.cars(rename=(MSPR=_mspr)); /* <<< added closing ')' */
mspr = input(_mspr,dolar10.);
drop _mspr;
fmtMSRP=input(MSRP,dolar10.);
run;
If MSRP is character then
msrp_numeric=msrp+0;
You can use INPUT either with INFILE or as a function.
To convert the char type to numeric you need a mid name:
data cars1;
set work.cars(rename=(MSPR=_mspr)); /* <<< added closing ')' */
mspr = input(_mspr,dolar10.);
drop _mspr;
fmtMSRP=input(MSRP,dolar10.);
run;
AS YOU CAN SEE THE DATA TYPE FOR MSRP IS CHAR BUT I WANT IT IN NUMERIC FOR FURTHER CALCULATION AND I WANT SAME VALUES LIKE $25,214 LIKE THIS BUT IN NUMERIC FORMAT...
code :-
data cars1;
set work.cars(rename=(MSRP=_msrp));
msrp = input(_msrp,dollar10.);
run;
THIS IS GIVING ME OUTPUT BUT NOW I WANT IT TO BE IN DOLLAR FORMAT LIKE $25,254 LIKE THIS BUT REEZA I AM SKIPPING SOMETHING
APPLY A FORMAT. OTHERWISE THE DEFAULT FORMAT IS BEST OR 8. WHICH HAS NO DOLLAR SIGNS. SO IF YOU WANT DOLLAR SIGNS YOU APPLY THE CORRECT FORMAT WHICH CONTROLS THE DISPLAY. NOTE THAT THE VALUE STORED IS STILL NUMERIC, FORMATS ONLY CONTROL THE DISPLAY OF THE DATA.
ALL CAPS is yelling on the internet. DON'T DO IT.
https://en.wikipedia.org/wiki/All_caps
And I did include the code, the format statement is in my post - add it into your current code.
You never posted the code/log and proc contents, ergo these circles.
I have edited my posted code. It should work.
@jonty wrote:
this is working fine btw any clue how to simplify it more ????
The best way is to read the data in correctly in the first place, but otherwise this is the simplest way to change the variable type.
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.